In my angularjs application, I have the following json.
$scope.itemsList = {
"busName": "ABC",
"needsToHide": true,
"num": 123
}, {
"busName": "xyz",
"needsToHide": false,
"num": 567
}, {
"busName": "pqr",
"needsToHide": true,
"num": 654
}, {
"busName": "lmn",
"needsToHide": false,
"num": 672
}
In my html I have simple ng-repeat :
<label ng-repeat="eachPosition itemsList track by eachPosition.num" ng-show="!eachPosition.needsToHide">
<span> {{eachPosition.busName}} </span>
</label>
Now I need to apply alternative colour using ng-class, to the visible labels only. I mean in the given list only "xyz" and "lmn" are visible on the screen and they should be given alternative colours.
How can I apply ng-class="{even: !($index%2), odd: ($index%2)}", in this case only for the visible labels, similar to below html, but that html should add even or odd classes correctly based on needsToHide flag?
<label ng-repeat="eachPosition itemsList track by eachPosition.num" ng-show="!eachPosition.needsToHide" ng-class="{even: !($index%2), odd: ($index%2)}">
<span> {{eachPosition.busName}} </span>
</label>
You can use
filterto do this.Example on jsfiddle.