我想实现此代码
a[10];
for(int i=3;i<7;i++)
a[i]
是否可以使用ng-repeat
实现这种类型的循环答案 0 :(得分:2)
你可以(即使它是丑陋的imho):
<div ng-repeat="int in ints | limitTo: -7 | limitTo: 4">
{{ int }} at {{ $index }}
</div>
答案 1 :(得分:1)
Angular过滤器很花哨,但是对于这个特定的用例你不需要它们,因为普通的javascript Array.prototype.slice
完全符合你的要求:
<div ng-controller="MyCtrl">
<!-- $scope.ints = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] -->
<div ng-repeat="int in ints.slice(3, 7)">
{{ int }} at {{ $index }}
</div>
</div>
结果:
3 at 0
4 at 1
5 at 2
6 at 3
答案 2 :(得分:0)
limitTo采用可选的第二个参数......