This works fine for a button or any other element, but the navbar flashes purple briefly and then goes back to the default color. I’'ve tried adding the class in “onPageDidEnter()” but this does not work.
Any help to get me on the right track would be appreciated.
ngAfterViewInit() {
this._app.getComponent('girl').elementRef.nativeElement.setAttribute('put the color you want here", true);
}
In my app, I am using it because I want to change the navbar color dependently of what the user will do and it works fine. I would prefer to have something like below, but it is not implemented yet
This will work if you want that specific color for that specific nav-bar. If you need something that will change depending of something else, then there is no easy way for now to do that, right?
Your solution would be perfect if we could make the attribute somehow dynamic, based on some value.
I tried that in the beginning but never managed to do it.
`<ion-navbar *navBar green *ngIf="greenCondition">
</ion-navbar>
<ion-navbar *navBar yellow *ngIf="yellowCondition">
</ion-navbar>
<ion-navbar *navBar black *ngIf="blackCondition">
</ion-navbar>
<ion-navbar *navBar purple *ngIf="purpleCondition">
</ion-navbar>
`
but this solution become weird things for much more than 4 condition. After 4th ion-navbar header (5th in-navbar) showns under main page headerbar. I can not handle this.
You might be interested in this approach. I think you would be able to combine it with @mhartington’s suggestion of custom attributes to localize all DOM-fiddling to a single directive, getting it out of your application controller code.
Update: the color attribute has been added to several components including the navbar and will be in the beta 12 release. See this issue for more information: https://github.com/driftyco/ionic/issues/7467
Make sure to check the changelog when beta 12 is released and follow the steps to upgrade.
Can I use the color attribute with colors that I don’t know ahead of time, i.e. colors that will be set dynamically by the user, or pulled from a database? Or do they have to be predefined SASS variables? I was expecting something like: