我想根据某些条件在表格单元格中显示具有替代颜色组合的文本,如下所示。
<tr ng-repeat="x in data">
<td>
<span ng-if="((x.time2 < x.time1) || (x.time2 < x.time3))" ng-style="color:red" {{x.val}}></span>
<span ng-if="((x.time2 === x.time1) && (x.time2 === x.time3)" ng-style="color:blue" {{x.val}}></span>
</td>
</tr>
但我没有得到以红色显示的值,尽管 x.time2 小于 x.time1。采样时间值为 time1="2017-03-15 06:06:56"、time2="2017-03-08 07:09:40"和 time3="2017-03-08 07:09:40"。所有时间值均为字符串格式。
最佳答案
尝试以这种方式更改您的代码:
<table>
<tbody>
<tr ng-repeat="x in data">
<td>
<span ng-if="x.time2 < x.time1 || x.time2 < x.time3" ng-style="{color: 'red'}" >{{x.val}}</span>
<span ng-if="x.time2 === x.time1 && x.time2 === x.time3" ng-style="{color: 'blue'}" >{{x.val}}</span>
</td>
</tr>
</tbody>
</table>
我还把 x.val
移到了 span 里面……不知道是不是出错了。
关于css - 使用 ng-if 和 ng-style 根据条件更改表格单元格文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42803209/