2014-09-11 79 views
-2
<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

什么错误?你期待它做什么?这不是程序员应该如何提出有关代码的问题。学习如何提出问题应该调试101. http://blog.codeunion.io/2014/09/03/teaching-novices-how-to-debug-code/ – BenCr 2014-09-11 10:34:04

回答

1

时,如果在阵列真正want to have duplicated items,一定要告诉角度来索引他们通过$index使角可以区分不同的物品:

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

错误说明了这一切: 错误:[ngRepeat :dupes]不允许在中继器中复制。使用'track by'表达式来指定唯一键。中继器:名称中的名称,重复键:字符串:pratik – Cathal 2014-09-11 10:10:19