爲什麼tab_cards
(對象數組)不能分配給$scope.cards
?如何以角度js顯示ng-repeat中的對象數組
HTML:
<div ng-app="trelloApp" id="cardContainer">
<div ng-controller="displayCardsCtrl">
<article ng-show="cards.length">
<ul id="card-list">
{{cards}}
<li ng-repeat="card in cards" >
<div class="view">
<center><h1>Titre:</h1></center>
<span>{{card.name}}</span>
<span class="close" ng-click="removeCard(card)">x</span>
</div>
</li>
</ul>
</article>
</div>
</div>
此Javascript之前我的代碼連接到Trello的API。
的Javascript:
var tab_cards = [];
var trelloApp = angular.module('trelloApp',[]);
Trello.get("/boards/M1msSdbt/cards", getCardsSuccess);
function getCardsSuccess(data){
for (var i = 0, l = data.length; i < l; i++){
tab_cards.push(data[i]);
}
}
trelloApp.controller('displayCardsCtrl',
function ($scope,tab_cards) {
$scope.cards = tab_cards;
});