【发布时间】:2014-09-30 06:27:22
【问题描述】:
rest api 在restangular get请求上返回一个json对象,响应只能在函数内部访问
Restangular.all('getUsers').getList().then(function(response) {
$scope.users = response;
angular.forEach($scope.users, function(value, key) { //This works
console.log(key + ': ' + value);
});
});
angular.forEach($scope.users, function(value, key) { //This does not work
console.log(key + ': ' + value);
});
【问题讨论】:
-
getList()是异步的。回调外部的forEach()在getList()返回并填充$scope.users之前运行。
标签: angularjs restangular