1

I have the following code:

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

There is any way to optimize this code? I think i have some repetition of ng-binding ...

user2864740
  • 60,010
  • 15
  • 145
  • 220
Christopher
  • 3,379
  • 7
  • 25
  • 36

1 Answers1

2

Could use ng-class and set your colors in css rules

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

Or do similar using ng-style

charlietfl
  • 170,828
  • 13
  • 121
  • 150