AngularJS:工厂中的调用承诺方法

AngularJS:工厂中的调用承诺方法,angularjs,angularjs-service,angularjs-factory,Angularjs,Angularjs Service,Angularjs Factory,我有一个如下方式的角度工厂,但当我尝试调用getDepositAccountDetailsService时,我得到以下错误: TypeError: this.getDepositAccountDetails.getDepositAccountDetailsService is not a function 如何称呼工厂内部的承诺 tellApp.factory('TabsFactory', function($resource){ var activetabs = {};

我有一个如下方式的角度工厂,但当我尝试调用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;
  });
控制器
我想你在代码中遗漏了一些东西

  • 从服务方法返回$resource
    getDepositAccountDetails

  • this.getDepositAccountDetails
    应该是
    activetabs.getDepositAccountDetails()
    ,因为您为工厂上下文创建了一个变量
  • 工厂

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

    activetabs.getDepositAccountDetails
    应该返回
    $resource
    对象,而不是
    这个.getDepositAccountDetails
    你应该执行
    activetabs.getDepositAccountDetails
    我已经返回了$resource,但是仍然是同样的问题,你是否遵循了我提到的第二件事……或者现在你添加了
    var-activetabs=this而不是
    var-activetabs={}抱歉,pankaj..我仍然收到相同的问题Peerror:activetabs.getDepositAccountDetails.getDepositAccountDetails服务不是function@vishnu很乐意帮忙,谢谢:)
    
    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;
    });