【发布时间】:2018-05-07 22:09:35
【问题描述】:
我正在创建一个表,其中包含从*ngFor 加载的一些行:
<tr *ngFor="let car of cars">
<td>{{car?.id}}</td>
<td>{{car?.date | date : "short"}}</td>
<div [ngSwitch]="car?.state">
<td *ngSwitchCase=1 class="col">Sold</td>
<td *ngSwitchCase=7 class="col">Repaired</td>
<td *ngSwitchDefault class="col">Out of stock</td>
</div>
</tr>
我希望每一行都涂上不同的颜色,这取决于汽车的状态。我知道如何处理静态内容,但如果它来自数据库则不知道,我必须使用 *ngFor 指令加载它。
当我使用引导程序时,我想对状态 1 使用类样式 .table-success,对状态 7 使用 .table-info,默认使用 primary。
<tr class="table-success">
【问题讨论】:
标签: angular html-table bootstrap-4 angular5 ngfor