ng-repeat counter in AngularJS

1.counter:

{{$index + 1}}

2.index as a class name:

%div{ng_class: "['for-' + $index]"}

result

<div class="for-0" ng_class="['for-' + $index]">  
  <h3 class="ng-binding">4601</h3>
  <div class="clearfix"></div>
</div>  

3.What if you want to start from 1?

%div{ng_class: "['for-' + {{ $index + 1 }}]"}

result

<div class="for-1" ng_class="['for-' + 1]">  
  <h3 class="ng-binding">4601</h3>
  <div class="clearfix"></div>
</div>  

That's all for now!

Victor Velazquez

Coder, Musician, Startups, Passionate Dancer & Life Lover. Software Engineer at MagmaLabs, Co-founder of Web Dev Talks, Co-founder of Voltaire, Co-founder of Paqkit, Ex-co-founder of Zaznova.

Subscribe to The zazvick's blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!