我有一个从服务器检索到的对象数组。查询工作,但是当我在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)',因为它具有相同的对象数组或不。 –