2014-09-11 75 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