【发布时间】:2019-01-07 00:31:07
【问题描述】:
我在表格中有一个 span 元素。我想根据值动态更改 css 类。
这是我的 html 代码:
<table>
<thead>
<tr>
<th>Fruits</th>
<th>Colors</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of fruits>
<td>{{data.fruits}}</td>
<td>
<span class="badge badge-default badge-success">{{data.color}}</span>
</td>
</tr>
</tbody>
</table>
我想根据我获得的数据显示徽章颜色。例如,如果我变红了,我想将徽章类别更改为徽章危险。如果我得到绿色,我想将课程更改为徽章成功等等。
如何在 Angular 4 中实现这一点?
谢谢
【问题讨论】: