我有一家工厂,如何在getAccountInformation()函数中调用“ getAccountDetails”服务。
我按以下方式尝试过,但无法正常工作。
AccountService.getAccountDetails.getAccountDetailsService
tellerApp.factory('AccountService',['$resource', function ($resource) {
return{
getAccountDetails: $resource(XXX, {}, {
getAccountDetailsService: {}
}),
getAccountInformation: function($scope, number, transaction, index){
AccountService.getAccountDetails.getAccountDetailsService({number : number})
.$promise.then(function(response){});
}
}]);
我建议您从返回的提供程序中定义代码依赖项:
tellerApp.factory('AccountService',['$resource', function ($resource) {
var getAccountDetails = $resource(XXX, {}, {getAccountDetailsService: {}});
return {
getAccountDetails : getAccountDetails,
getAccountInformation: function($scope, number, transaction, index){
getAccountDetails.getAccountDetailsService({number : number}).$promise.then(function(response){
...
})
}
};
}]);
或者,在一个对象内部,您也可以使用this
引用当前对象,而不是使用AccountService.getAccountDetails
,而应该使用this.getAccountDetails
。
tellerApp.factory('AccountService',['$resource', function ($resource) {
return {
getAccountDetails : $resource(XXX, {}, {getAccountDetailsService: {}});,
getAccountInformation: function($scope, number, transaction, index){
this.getAccountDetails.getAccountDetailsService({number : number}).$promise.then(function(response){
...
})
}
};
}]);
另外,请注意,因为您的命名约定令人困惑(getAccountDetails
不是函数,因为您不使用对其进行调用()
,但是它的名称为“ get”,getAccountServices
因此首先被定义为对象,但是稍后将相同的名称用于功能...),特别是如果您想要一个准确的答案;)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句