我有以下代码:
<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绑定的重复
可以使用ng-class
并在css规则中设置颜色
<span ng-bind="status"
ng-class="{'green-class': status=='OK', 'red-class': status=='NOT OK'}" ></span>
或者使用ng-style