How to change icon color dynamically

My app has a dynamic list of buttons icon when user clicks on the icon an backed process is done if sucessful, I want to toggle the color from
Danger to secondary or vise versa.

How can I do that.

you can set attrs directly in the template.

In ionic 2 you can set directives/attributes like danger, favorite, …

So you can do this:

<button (click)="..." [attr.danger]="isPending ? '' : null">Send</button>

In this case danger is added, while your request is processing and your button is red.

In other cases you can use ngClass to set custom classes or ngStyle to set multiple custom css inline styles.

1 Like