gpt4 book ai didi

javascript - Angular 渲染元素但不显示数据

转载 作者:行者123 更新时间:2023-11-30 11:58:31 27 4
gpt4 key购买 nike

我正在从资源工厂接收数据,但是当我尝试输出它时它呈现了元素,但仍然是空的。这很奇怪,因为我可以在控制台日志中看到它已解决。

Controller

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'}}
});
});

最佳答案

您将值分配两次(第二次分配给 promise )。

尝试

dichotomy.controller('WorkplaceOverview', ['$scope', 'WorkPlace', function ($scope, WorkPlace) {
WorkPlace.all({get_all:1}).$promise.then(function (response) {
$scope.workplaces = response;
console.log($scope.workplaces);
});
}]);

关于javascript - Angular 渲染元素但不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37241885/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com