是否可以通过从某个索引开始循环并在另一个索引处结束来将显示结果的数量限制为 "ng-repeat"
is it possible to limit the number of displayed results by "ng-repeat" by starting the loop from some index and ending it at some another
我想实现这段代码
a[10];
for(int i=3;i<7;i++)
a[i]
是否可以使用 ng-repeat 实现这种类型的循环
limitTo 采用可选的第二个参数...
你可以(即使是丑陋的恕我直言):
<div ng-repeat="int in ints | limitTo: -7 | limitTo: 4">
{{ int }} at {{ $index }}
</div>
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
我想实现这段代码
a[10];
for(int i=3;i<7;i++)
a[i]
是否可以使用 ng-repeat 实现这种类型的循环
limitTo 采用可选的第二个参数...
你可以(即使是丑陋的恕我直言):
<div ng-repeat="int in ints | limitTo: -7 | limitTo: 4">
{{ int }} at {{ $index }}
</div>
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