这是我的index.js
import ProductDetailController from './product-detail.controller.js';
import ProductDetailManager from './product-detail.manager.js';
import ProductDetailService from './../services/product-detail.service.js';
export default angular.module('myApp.productDetail', [uirouter])
.controller('ProductDetailController', ProductDetailController)
.service('productDetailManager', ProductDetailManager)
.service('productDetailService', ProductDetailService)
.name;
这是我的控制器
export default class ProductDetailController {
constructor( logger, productDetailManager, $stateParams) {
this.productDetailManager = productDetailManager;
this.activate();
}
activate() {
return this.loadProduct(this.$stateParams.boutiqueId,this.$stateParams.productId).then(()=> {
});
}
loadProduct(boutiqueId, productId) {
//async
return this.productDetailManager.getProduct(boutiqueId, productId).then((response)=> {
return this.response;
});
}
}
ProductDetailController.$inject = [ 'logger', 'productDetailManager', '$stateParams'];
这是我的经理
export default class ProductDetailManager {
constructor( logger, productDetailService) {
this.productDetailService = productDetailService;
this.logger = logger;
}
getProduct(boutiqueId, productId) {
//async
return this.productDetailService.find(boutiqueId, productId).then((response)=> {
console.log(this.response);
return this.response;
});
}
}
ProductDetailManager.$inject = [ 'logger', 'productDetailService'];
这是我的服务
export default class ProductDetailService {
constructor($http, $q, logger, configurationService) {
this.$http = $http;
this.$q = $q;
this.logger = logger;
this.configurationService = configurationService;
this.basePath = this.configurationService.get('catalogApiBasePath');
}
find(boutiqueId, productId) {
var deferred = this.$q.defer();
this.$http.defaults.headers.common.Authorization = 'Bearer ---';
this.$http.defaults.headers.common.X_AUTH_VERSION = '---';
this.$http.get(`${this.basePath}/product/detail?boutiqueId=${boutiqueId}&productId=${productId}`)
.success((data, status, headers, config)=> {
deferred.resolve(data);
})
.error((data, status) => {
this.logger.error('XHR Failed for ProductDetailService#find.' + data);
deferred.reject(data);
});
return deferred.promise;
}
}
ProductDetailService.$inject = ['$http', '$q', 'logger', 'configurationService'];
我想在我的经理上更改服务数据然后返回控制器,但是管理员正在获取未定义的数据。
我对异步调用做错了,找不到我在这里缺少的东西
答案 0 :(得分:0)
我猜错误就在这里:
return this.productDetailService.find(boutiqueId, productId).then((response) => {
console.log(this.response); // here should be just `response` as it is argument
return this.response;
});