Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change icon in angular 6

I am trying to change the font-awesome icon depending on a certain value but it stays set to the original icon even after my model has changed. Here is my code

In Controller

if (foo.change < 0) {
   foo.icon = "fa fa-sort-down";
} else {
  foo.icon = "fas fa-sort-up";
}

In my HTML

<i [className]="foo.icon"></i>

Is there a way to update an icon dynamically based on a model or a check?

like image 307
inhaler Avatar asked Dec 18 '22 16:12

inhaler


1 Answers

use [ngClass]

<i  [ngClass]="foo.change < 0 ? 'fa fa-sort-down' : 'fas fa-sort-up'"></i>
like image 79
Vamsi Ambati Avatar answered Jan 04 '23 06:01

Vamsi Ambati