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:
我正在尝试找到一些文档,以便能够将计数的数字附加到ng-repeat返回的每个项目中。对于Angular来说,这不是一个盒子里的东西吗?不太像Id,但更像是,如果返回4个项目,每个项目JSON对象可以在返回的数据前面添加一个数字。我的代码看起来像:
<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>
2 个解决方案
#1
6
You can use $index for your counter.
你可以使用$ index作为你的柜台。
<div class="swipeBoxes" ng-repeat="swipe in swipes">
{{$index + 1}}
</div>
#2
#1
6
You can use $index for your counter.
你可以使用$ index作为你的柜台。
<div class="swipeBoxes" ng-repeat="swipe in swipes">
{{$index + 1}}
</div>