gpt4 book ai didi

angularjs - Angular .then() 无法识别

转载 作者:行者123 更新时间:2023-12-04 13:03:33 25 4
gpt4 key购买 nike

我尝试在我的 Angular Controller 中使用 .then()

 angular.module('n2goApp')
.controller('MainCtrl', function($scope, Products) {
Products.get(). then( function ( response ) {
$scope.data = response;
console.log(response);
$scope.totalPages = response.TotalPages;
$scope.totalItems = response.total;
$scope.products = response.data;
$scope.currentPage = response.current_page;
$scope.maxSize = 5;
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
});
});

但给我一个错误
Error: Products.get(...).then is not a function

服务
angular.module('n2goApp')
.service('N2goservice', function N2goservice() {
// AngularJS will instantiate a singleton by calling "new" on this function
}).factory('Products', ['$resource', function($resource) {

var url = 'http://domain.com/api/products';
return $resource( url + '/:prodID',
{ bookId: '@prodID' }, {
loan: {
method: 'PUT',
params: { prodId: '@prodID' },
isArray: false
},
get:{
method: 'GET',
params: {
prodId: '@prodID',
page:'@page'
},
isArray: false
}
/* , method3: { ... } */
} );

}]);

我做错了什么?

最佳答案

您必须从资源中获取 $promise。像这样:

Products.get().$promise.then(..)

关于angularjs - Angular .then() 无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24467248/

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