2016-09-19 55 views
0

我試圖顯示cList中的每個項目,但它不工作。它創建正確數量的div標籤(來自ng-repeat),但它們是空的。它看起來像項目是不確定的,所以沒有顯示。angularjs ng-repeat item is undefined

這是控制器:

var app = angular.module('MyApp'); 

app.controller('listController', function($scope) { 
    $scope.cList = [ 'c1', 'c2', 'c3', 'c4', 'c5' ]; 
}); 

這是HTML:

<div ng-controller="listController"> 
    <div ng-repeat="item in cList"> 
    {{item}} 
    </div> 
</div> 

它產生這個HTML重複5次:

<div ng-repeat="item in cList" class="ng-scope"> 

</div> 
<!-- end ngRepeat: item in cList --> 

如果我把別的東西在ng-repeat中的div標籤,它將在頁面上顯示5次。有沒有任何理由,該項目將不明確?

+0

替換下面的代碼

 var app = angular.module('MyApp'); 

你檢查回答? – Sajeetharan

+0

@sajeetharan它沒有解決問題。這可能是項目設置方式的問題嗎? – Neil

+0

你能給我團隊查看器嗎? – Sajeetharan

回答

1

添加空的依賴數組你的模塊,

var app = angular.module("MyApp", []); 

<body ng-app='myApp' > 
    <div ng-controller="listController"> 
    <div ng-repeat="item in cList"> 
     {{item}} 
    </div> 
    </div> 
    </body> 

WORKING DEMO

0

您需要這方面的

var app = angular.module('MyApp',[]);