【发布时间】:2018-09-15 21:22:31
【问题描述】:
我想根据ng-repeat 产生的值设置表格单元格的背景。到目前为止,我有以下代码:
<table id="myTableDisk" width="100%" border="1">
<tbody>
<tr>
<th scope="col">Mount</th>
<th scope="col">Size</th>
<th scope="col">Used</th>
<th scope="col">Free</th>
<th scope="col">Use %</th>
</tr>
<tr ng-repeat="mount in msg.payload"
ng-style="{backgroundColor: $scope.getBackgroundColor(mount.usedPercent)}"
$scope.getBackgroundColor(value) {
if(value <= 75)
return 'red';
if(value > 90)
return 'blue';
return 'black'
}>
<th align="left" scope="row">{{mount.mount}}</th>
<td align="right">{{mount.size}}</td>
<td align="right">{{mount.used}}</td>
<td align="right">{{mount.available}}</td>
<td align="right">{{mount.usedPercent}}</td>
</tr>
</tbody>
</table>
现在我不得不对这段代码提出问题:
- 它不起作用
- 如果可行,我认为它会为整个表格着色,但我只需要在
{{mount.usedPercent}}td 上工作
在 Angular 中实现这一点的实用方法是什么?
【问题讨论】:
标签: html angularjs angularjs-ng-repeat