Omprakash Sharma Omprakash Sharma - 2 months ago 7
AngularJS Question

pass index to ng-class with ng-repeat

I want to increment class sequence with

ng-repeat
.
My requirement meets like

<div class="c1">image1</div>
<div class="c2">image2</div>
<div class="c3">image3</div>
......................
<div class="cN">imageN</div>


I tried to reduce this as

<div ng-class="{'c':{{imgNo}}}" ng-repeat="imgNo in imgNos">Image{{imgNo}}</div>


or

<div ng-class="{'c[$index]':isTrue}" ng-repeat="imgNo in imgNos">Image{{imgNo}}</div>


Please help me with the correct way. Thanks

Answer

Try this

<div class="c{{imgNo}}" ng-repeat="imgNo in ImgNos">Image{{imgNo}}</div>

DEMO

Comments