我有一個從服務器檢索到的對象數組。查詢工作,但是當我在HTML視圖中執行ng-repeat
時,它不起作用,它不顯示任何內容。爲什麼? 這是js代碼:在數組中的對象的Ng重複不起作用
$scope.companyList = [];
$scope.getCompanyList = function() {
$scope.companyList.length = 0;
CompanyListSrv.getCompanyListDetail(function (companyListDetail) {
if (companyListDetail) {
$scope.companyList = companyListDetail;
}
});
};
$scope.getCompanyList();
HTML代碼:
<tr ng-repeat="company in companyList">
<td>{{ company.name }}</td>
<td>{{ company.email }}</td>
</tr>
這是companyListDetail陣列(從服務器響應):
companyListDetail: Array[2]
0: Object
1: Object
length: 2
這是0: Object
:
email: "[email protected]"
name: "Compant 2"
在控制檯我沒有錯誤,並在瀏覽器的HTML頁面我有這樣的:
<!-- ngRepeat: company in companyList -->
不能看到obvios錯誤。請嘗試檢查下一個: 1.您如何使用異步呼叫?使用$ http?嘗試把 $ timeout(function(){$ scope.companyList = companyListDetail;}); 2.將 的console.log(companyListDetail)剛過功能(companyListDetail){調用函數$ scope.getCompanyList(後 – Vitalii
看跌的console.log($ scope.companyList)),並檢查是否有可用的數據或不。問題可能是數據(** companyList **)不可用於ng-repeat –
檢查'$ scope.companyList = companyListDetail;''console.log($ scope.companyList)',因爲它具有相同的對象數組或不。 –