我有一个角度工厂,但是当我尝试调用 getDepositAccountDetailsService 时,我收到以下错误:
TypeError: this.getDepositAccountDetails.getDepositAccountDetailsService is not a function
如何在工厂内致电承诺。
tellApp.factory('TabsFactory', function($resource){
var activetabs = {};
activetabs.getDepositAccountDetails = function(){
$resource('XXXXXXX/:number', {}, {
getDepositAccountDetailsService: { method: 'GET', isArray: false}
});
}
activetabs.setAccountInfo = function(accountnumber, result) {
var accountinit = {
accountInfo:[]
};
if(result.code == "s") {
this.getDepositAccountDetails.getDepositAccountDetailsService({number : accountnumber}).$promise.then(function(response){
return accountinit.accountInfo = response;
}, function(error) {
});
}
}
return activetabs;
});
$scope.accountInfo = TabsFactory.setAccountInfo(accountnumber, $scope.result);
答案 0 :(得分:1)
我认为你错过了代码中的几件事,
getDepositAccountDetails
this.getDepositAccountDetails
应为activetabs.getDepositAccountDetails()
,因为您为工厂上下文创建了一个var。<强>工厂强>
tellApp.factory('TabsFactory', function($resource) {
var activetabs = {};
activetabs.getDepositAccountDetails = function() {
return $resource('XXXXXXX/:number', {}, {
getDepositAccountDetailsService: {
method: 'GET',
isArray: false
}
});
}
activetabs.setAccountInfo = function(accountnumber, result) {
var accountinit = {
accountInfo: []
};
if (result.code == "s") {
activetabs.getDepositAccountDetails().getDepositAccountDetailsService({
number: accountnumber
}).$promise.then(function(response) {
return accountinit.accountInfo = response;
}, function(error) {
});
}
}
return activetabs;
});