angular - 在 Ionic 2 中动态改变颜色

标签 angular styles ionic2

基于某些条件,我试图设置元素的颜色值。

因此,在我的 TS 文件中,我采用了一个名为 color 的变量,我将其设置为

  if(this.value>0) this.color="#ffc000!important";

在我的 HTML 文件中,我尝试通过以下方式设置这种颜色

<ion-icon name="notifications" [style.color]="color">

以及使用 ngstyle

<ion-icon name="notifications" [ngStyle]="{'color': color}">

这些都不起作用。我哪里做错了或者正确的做法是什么?

最佳答案

<ion-icon name="notifications" [color]="color">

希望这能行得通

关于angular - 在 Ionic 2 中动态改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41342989/

相关文章:

html - 无法在字符串 'validator' 上创建属性 'userForm' - 使用组件工厂

javascript - 如何在 Angular 6 中使用新的 RXJS 6 管道/映射返回解析数据?

angular - Ionic 3 组件上的防护装置

带有 Jasmine/Karma 的 Angular Mock 字段/属性

Angular 无法在 Chrome 中运行

css - 媒体查询 : same height and different width

c# - XAML 中的 MergedDictionaries 重写为代码

html - 网站内容被切断

angular - Angular2 中的复选框组处理和验证

javascript - 使用jquery以编程方式触发ionic 3元素的点击事件