我正在尝试为10个元素的JSON进行ng-repeat。我想从ng元素中运行和显示ng-repeat。我怎么能这样做?
<div ng-repeat="item in myarray>
{{item.name}}
</div>
$scope.myarray=
[
{"name":"joe"},
{"name":"ana"},
{"name":"buf"},
{"name":"yei"},
{"name":"jsi"},//5
{"name":"sda"},
{"name":"jofrewe"},
{"name":"re"},
{"name":"we"},
{"name":"we1"}
]
结果应该是:
sda
jofrewe
re
name
we1
答案 0 :(得分:1)
我建议使用ng-show
隐藏一些元素。
const app = angular.module("demo", []);
app.controller("test", function($scope) {
$scope.myarray=
[
{"name":"joe"},
{"name":"ana"},
{"name":"buf"},
{"name":"yei"},
{"name":"jsi"},
{"name":"sda"},
{"name":"jofrewe"},
{"name":"re"},
{"name":"we"},
{"name":"we1"}
];
$scope.min = 4;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="demo" ng-controller="test">
<input type="range" ng-model="min"
min="0" max="10"/>
<div ng-repeat="item in myarray" ng-show="$index>=min">
{{item.name}}
</div>
</div>
答案 1 :(得分:0)
你可以手动完成:
ng-repeat="item in myarray.slice(4, myarray.length)"
虽然不一定干净或漂亮。
答案 2 :(得分:0)
您可以在ng-repeat
指令中提供真实的表达式。所以只需使用slice从数组中获取所需的元素:
<div ng-repeat="item in myarray.slice(5)">
{{item.name}}
</div>