admin管理员组文章数量:1336643
I am trying to find some documentation for being able to append a counted number to each item returned by an ng-repeat. Is this not an out of a box thing for Angular? Not quite like an Id, but more like, if 4 items returned, each item JSON object could add a number in front of data returned. My code looks like:
<div class="swipeBoxes" ng-repeat="swipe in swipes">
<a href="#">
<div class="swipeBox">
<span class="swipeNum"></span>
<p><span>swipe date:</span><span>{{ swipe.date | date: 'MM/dd/yyyy'}}</span></p>
<p><span>provider:</span><span>{{ swipe.merchant }}</span></p>
<p><span>amount:</span><span>{{ swipe.amount | currency }}</span></p>
</div>
</a>
</div>
I am trying to find some documentation for being able to append a counted number to each item returned by an ng-repeat. Is this not an out of a box thing for Angular? Not quite like an Id, but more like, if 4 items returned, each item JSON object could add a number in front of data returned. My code looks like:
<div class="swipeBoxes" ng-repeat="swipe in swipes">
<a href="#">
<div class="swipeBox">
<span class="swipeNum"></span>
<p><span>swipe date:</span><span>{{ swipe.date | date: 'MM/dd/yyyy'}}</span></p>
<p><span>provider:</span><span>{{ swipe.merchant }}</span></p>
<p><span>amount:</span><span>{{ swipe.amount | currency }}</span></p>
</div>
</a>
</div>
Share
Improve this question
asked Jan 19, 2016 at 22:50
MarkMark
1,8724 gold badges31 silver badges54 bronze badges
3
-
3
you can use
$index
inside of anng-repeat
...is this what you are looking for? – Logan Murphy Commented Jan 19, 2016 at 22:53 - 2 <div ng-repeat="swipe in swipes track by $index"> – Himmel Commented Jan 19, 2016 at 22:54
- 1 Right in the documentation: docs.angularjs/api/ng/directive/ngRepeat – epascarello Commented Jan 19, 2016 at 22:58
2 Answers
Reset to default 7You can use $index for your counter.
<div class="swipeBoxes" ng-repeat="swipe in swipes">
{{$index + 1}}
</div>
Using $index
from ngRepeat should be able to solve your problems.
本文标签: javascriptAdd a counter to Angular ngrepeatStack Overflow
版权声明:本文标题:javascript - Add a counter to Angular ng-repeat? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742417556a2471010.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论