假设我有以下角表
<table>
<tr *ngFor="let company of investTable; let i = index">
<td>
{{company.name}}
</td>
<td>
{{company.price}}
</td>
<td>
{{company.profit}}
</td>
</tr>
</table>
我怎样才能使表格单元格根据单元格值的不同而有不同的背景色呢? 比如说,如果公司利润是正值,就把它变成绿色。
在css
td.highlight {
background-color: green;
}
在html中:-
<table>
<tr *ngFor="let company of investTable; let i = index">
<td>
{{company.price}}
</td>
<td [ngClass]="{'highlight': company.profit > 0}">
{{company.profit}}
</td>
</tr>
</table>
你可以在你的html中加入这个。
<td [style.positive]="company.profit > 0">
在你的css中加入这个。
td.positive{
background-color: green;
}