I have a simple ng-repeat
that displays a list of scores and a value of either Positive or Negative.
What i am trying to do is when the value is Negative, display a red background CSS class, and when Positive, display a green CSS class. However, for some reason, i am always seeing the red CSS class on my page.
HTML:
<tr ng-repeat="scores in Test" ng-class="{true: 'warning', false: 'ok'}[scores.Indicator == 'Negative']">
<td>Overall: {{ scores.Indicator }}</td>
</tr>
CSS:
.warning {
background: red;
}
.ok {
background: green;
}
I haven't seen that particular syntax used before, what's the rationale behind
{true: 'warning', false: 'ok'}[scores.Indicator == 'Negative']
?The way I would use
ngClass
here isDoes that work?
For better readability you could delegate it to the controller as well
Or you could create a directive