我正在尝试根据某个值更改 font-awesome
图标,但即使在我的模型更改后它仍然设置为原始图标。这是我的代码
在 Controller
中
if (foo.change < 0) {
foo.icon = "fa fa-sort-down";
} else {
foo.icon = "fas fa-sort-up";
}
在我的
HTML
中<i [className]="foo.icon"></i>
有没有办法根据
model
或 check
动态更新图标?
最佳答案
我在网上找到了 this:
The error is due to the fontawesome JS library wich dynamically replace the elements defined with specific classes by svg elements sharing attributes of the initial element, so you cannot use the element tag name to select it: you need to select the new svg created element by another way
因此,最简单的解决方案是:
<i *ngIf="foo.change < 0" [className]="fa fa-sort-down"></i>
<i *ngIf="foo.change >= 0" [className]="fas fa-sort-up"></i>
关于angular - 动态更改 Angular 6 中的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57587242/