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 is
<tr ng-repeat="scores in Test" ng-class="{warning: (scores.Indicator == 'Negative'), ok: (scores.Indicator != 'Negative')}">
Does that work?
For better readability you could delegate it to the controller as well
<tr ng-repeat="scores in Test" ng-class="scoreClass(scores)">
$scope.scoreClass = function(scores) {
return scores.Indicator == 'Negative' ? 'warning': 'ok';
}
Or you could create a directive
<tr ng-repeat="scores in Test" score-class scores="scores">
.directive('scoreClass', [function() {
return {
restrict: 'A',
scope: {
scores: '=',
},
link: function(scope, element, attrs, controller) {
scope.$watch('scores', function() {
element.removeClass('ok');
element.removeClass('warning');
if (scope.scores.Indicator == 'Negative') {
element.addClass('warning');
} else {
element.addClass('ok');
}
}, true);
}
};
}]);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…