我正在从资源工厂接收数据,但是当我尝试输出它时,它会渲染元素,但仍然是空的。这很奇怪,因为我可以在控制台日志中看到它已解决。
控制器
dichotomy.controller('WorkplaceOverview', ['$scope', 'WorkPlace', function ($scope, WorkPlace) {
$scope.workplaces = WorkPlace.all({get_all:1}).$promise.then(function (response) {
$scope.workplaces = response;
console.log($scope.workplaces);
});
}]);
工厂
dichotomy.factory('WorkPlace', function ($resource) {
return $resource('api/create_workplace/:id/:get_all/', {}, {
all: {method: "GET", isArray: true, params: {get_all: '@get_all'}},
get: {method: "GET", isArray: false, params: {id: '@id'}},
update: {method: 'PUT', params: {id: '@id'}}
});
});
答案 0 :(得分:3)
您将值分配两次(第二次是承诺)。
尝试
dichotomy.controller('WorkplaceOverview', ['$scope', 'WorkPlace', function ($scope, WorkPlace) {
WorkPlace.all({get_all:1}).$promise.then(function (response) {
$scope.workplaces = response;
console.log($scope.workplaces);
});
}]);