css - 使用 ng-if 和 ng-style 根据条件更改表格单元格文本颜色

标签 css angularjs html-table

我想根据某些条件在表格单元格中显示具有替代颜色组合的文本,如下所示。

<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/

相关文章:

css - IE8、IE7、IE6,td的高度相差1px

Javascript 为多个元素设置 CSS 类(一个元素集,其余元素未设置)

html - 如何使用 CSS 制作折叠丝带效果?

javascript - 无法设置未定义的属性 'helloMessage'

angularjs - AngularJS 对多页面应用程序有用吗

html - 根据表格行的大小更改图像的大小

html - IE7 <li> 元素符号或数字显示在 div 之外

jquery - 在滚动条上交叉淡入淡出固定背景图像

javascript - 从rest服务获取JSON字符串到js

html - 将边框应用于 tfoot 的 CSS 选项?使用 "border-top"设计 tfoot 不起作用