<input type="number" ng-model="limit"/>
<button ng-click="runNames()" />
<div style="height:150px;width:150px" class="boxed" ng-repeat="name in names">
{{name|uppercase}}
</div>
mainModule.controller('helloWorldController', ['$scope', function ($scope) {
$scope.runNames = function () {
$scope.names = [];
for (i = 0; i < $scope.limit; i++) {
$scope.names.push("pratik");
}
};
}]);
答案 0 :(得分:1)
如果您确实在数组中want to have duplicated items,请确保告诉Angular按$index
索引它们,以便Angular可以区分各个项目:
<div ng-repeat="name in names track by $index">
{{name|uppercase}}
</div>