[ngClass]
如果值是您想要的值,则可以使用和应用类。
在这里,使用这个:
<table border="1">
<thead>
<td>Reading Time</td>
<td>PH</td>
</thead>
<tbody>
<tr *ngFor='let element of ph'
[ngClass]="{'color': (element.ph > 20 && element.ph < 50)}">
<td>{{element.timestamp}}</td>
<td>{{element.ph}}</td>
</tr>
</tbody>
</table>
另外,根据Yoel Rodriguez的建议,您还可以使用[class.color]
它动态地应用它:
<table border="1">
<thead>
<td>Reading Time</td>
<td>PH</td>
</thead>
<tbody>
<tr *ngFor='let element of ph'
[class.color]='element.ph > 20 && element.ph < 50'>
<td>{{element.timestamp}}</td>
<td>{{element.ph}}</td>
</tr>
</tbody>
</table>
这是color
css类:
.color {
color: white;
font-weight: bold;
background-color: red;
}
PS:我并不是在建议这种[ngStyle]
方法,因为编写内联样式并不是真正的好习惯。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句