我試圖訪問對象的數組在我的控制器:
AngularJS - 訪問對象的數組中的一個控制器發生故障
angular.module('schoolManagement').controller('CycleController', ['$scope', function($scope){
$scope.cycles = [
{
nomCycle : 'Primaire',
active : 'oui'
},
{
nomCycle : 'Collège',
active : 'non'
}
];
console.log($scope.cycles[0].nomCycle);
}]);
的的console.log()給正是我要找的控制檯,但是當我在我看來,在陣列上使用NG-重複循環,這是行不通的:
<tbody ng-controller="CycleController as CycleCtrl">
<tr ng-repeat="cycle in CycleCtrl.cycles">
<td>
<input type="checkbox" />
</td>
<td>{{cycle.nomCycle}}</td>
<td>{{cycle.active}}</td>
</tr>
</tbody>
編輯:
由於我使用$scope
也沒有必要使用控制器的語法,在這個正確的形式:
<tr ng-repeat="cycle in cycles">...</tr>
您正在使用控制器別名語法,並嘗試從控制器實例獲取屬性時,它被分配給範圍屬性。 – PSL