Reputation: 9196
I'm just starting out with angular. I currently have an json array of products being displayed within an ng-repeat and am looking to add a class to every third product.
Is there a way to write a condition within the repeater that will add a class to the html element when the index%3 is 2
Thanks
Upvotes: 2
Views: 1928
Reputation: 26880
Yes, use the ng-class
directive:
<div ng-repeat="item in items" ng-class="{ 'third-elm': $index%3 == 2 }">{{item.value}}</div>
jsFiddle: http://jsfiddle.net/bmleite/dKjz5/
Upvotes: 0
Reputation: 19401
Sure!
<div ng-repeat='item in items' ng-class='{third: $index%3==2}'>{{item}}</div>
http://plnkr.co/edit/24Ne1Cyh71INYIKxBCcc
Upvotes: 5