【问题标题】:Angular 7 change color of text based on value from JSON listAngular 7根据JSON列表中的值更改文本颜色
【发布时间】:2019-12-22 06:36:34
【问题描述】:

如果值来自列表,我正在尝试更改某些文本的颜色。如果值小于或等于 4 则为红色,如果大于 4 则为绿色。

基于这个问题和答案 - change the font color based on value angular js

我写了以下内容:

   <mat-card-header ng-repeat="let item of lstonofflinegt1">
            <mat-card-title>My Title</mat-card-title>
            <mat-card-subtitle ng-class="{'color:#2ecc71': item.value > 4, 'color:#e74c3c': item.value < 4}">ONLINE</mat-card-subtitle>
    </mat-card-header>

文本没有任何反应。我错过了什么?

【问题讨论】:

  • 您正在添加样式属性 insted of class
  • 代替 ng-class 试试 ngStyle
  • 如果这是 Angular 7,你为什么要使用 ng-repeatng-class

标签: css angular


【解决方案1】:

试试这个 &lt;mat-card-subtitle [ngStyle]="{'color': item.value &gt; 4 ? '#2ecc71': '#e74c3c'}"&gt;ONLINE&lt;/mat-card-subtitle&gt;

【讨论】:

    猜你喜欢
    • 2019-08-24
    • 1970-01-01
    • 2021-11-17
    • 2017-03-09
    • 1970-01-01
    • 2017-06-15
    • 2019-09-17
    • 2019-06-26
    • 1970-01-01
    相关资源
    最近更新 更多