You could use an array and make the expression much concise and readable:
<div class="tag"
ng-class="[{0:'blue1', 1:'blue2', 2:'blue3'}[k], v.direction]">{{v.term}}</div>
You just have to take care of "stagnant" class being set via css (or do [{0:'blue1', 1:'blue2', 2:'blue3'}[k], v.direction === 'stagnant' ? '' : v.direction]
). ng-class
is flexible that you can use an array of expression or string as well. In this case first value in the array is an object literal {0:'blue1', 1:'blue2', 2:'blue3'}[k]
with a bracket notation to evaluate the value out of the array based on the key passed in by k
and second value of array is the v.direction
itself.
Demo
.blue1 {
color: blue;
}
.blue2 {
color: green;
}
.blue1 {
color: red;
}
.negative {
background-color: #ccc;
}
.positive {
background-color: #123;
}
.stagnant {
background-color: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app ng-init="k=1;v.direction='positive'">
<div class="tag" ng-class="[{0:'blue1', 1:'blue2', 2:'blue3'}[k], v.direction]">Term</div>
</div>
Sometimes a general thumb rule is that when you have a longer expression it should not be in the view, instead should be in the controller. So you could as well create a controller function and return the expected classes as an object literal and bind the function to ng-class.