运行以下代码时出现角度抛出错误

时间:2014-09-11 09:59:01

标签: angularjs

<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");
        }
    };
}]);

1 个答案:

答案 0 :(得分:1)

如果您确实在数组中want to have duplicated items,请确保告诉Angular按$index索引它们,以便Angular可以区分各个项目:

<div ng-repeat="name in names track by $index">
    {{name|uppercase}}
</div>