@icarus_31 oh I thought you were talking about changing the color of the icon dynamically, sorry! Yes, changing name will dynamically change the icon, and I believe we will be adding a color attribute. Keep an eye on this issue for everything icons:
and it doesn’t change the color of the button. I can solve this issue with ngClass approach but I think this is not a good way. Does ionic have some issues for now with [attr.outline]="!item.subscribed ? '' : null" or I’m doing something wrong?
It’s also not working in beta.4 either. Looks like it may not be at the top of their priority list, which stinks, as I am unable to implement a whole section of my app without it.
@mpaland@jbardi This is fixed in beta.3 - check out this plunker demo . I guess that the problem is that you’re either not correctly setting the attribute or you haven’t declared the color that you’re using. Also make sure to use color names defined in the $colors list in app.variables.scss(or add custom colors there) as shown in the example below:
// test.ts
// ...
export class TestPage {
myColor: string;
constructor() {
// Invalid - it should be a name of a color as defined in the $colors list.
//this.myColor = '#123456';
// This won't work either, unless it's declared in the $colors list.
//this.myColor = 'nonexistent';
// This works as expected.
this.myColor = 'secondary';
// This works too, when it's declared in the $colors list.
this.myColor = 'facebook';
}
// ...
}
@iignatov, thanx for giving further explanation.
I have custom colors and can’t use predefined scss vars.
What I tried is to set this.myColor to ‘red’ or to ‘#FF0000’.
This is not working.
In fact, and that’s maybe what @jbardi is looking for, you can use:
@mpaland With custom colors the obvious choice is [style.background-color] as you already mentioned.
AFAIK the button’s color attribute in Ionic 2 is intended to be used only with names of colors defined in the $colors list in app.variables.scss. The fact that it’s not working with color values is not a bug, it’s a design decision. And this makes sense because its goal is not to save a few keystrokes (compared to using [style.background-color]) but to allow the use of predefined colors (i.e. the ones from the $colors list) which are otherwise not easily accessible in the code.
I guess that the docs should be updated to clarify this.