1

我有以下代码:

<span ng-switch="status">
    <span ng-switch-when="NOT OK">
        <span style="color: red;" ng-bind="status"></span>
    </span>
    <span ng-switch-when="OK">
        <span style="color: green;" ng-bind="status"></span>
    </span>
    <span ng-switch-default>
        <span ng-bind="status"></span>
    </span>
 </span>

有什么办法可以优化这段代码?我想我有一些重复的 ng-binding ...

4

1 回答 1

2

ng-class可以在 CSS 规则中使用和设置颜色

<span ng-bind="status" 
      ng-class="{'green-class': status=='OK', 'red-class': status=='NOT OK'}" ></span>

或者做类似的使用ng-style

于 2015-08-11T01:04:22.140 回答