1

I have a angular factory in the following way , but when i try to call getDepositAccountDetailsService i am getting the following error:

TypeError: this.getDepositAccountDetails.getDepositAccountDetailsService is not a function

How to call the promise inside factory.

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

controller

$scope.accountInfo = TabsFactory.setAccountInfo(accountnumber, $scope.result);
3
  • 1
    activetabs.getDepositAccountDetails should return $resource object & instead of this.getDepositAccountDetails you should do activetabs.getDepositAccountDetails Commented Apr 14, 2015 at 10:13
  • I have returned the $resource, but still the same issue Commented Apr 14, 2015 at 10:24
  • did you followed my second thing which i mentioned..or now you add var activetabs = this; instead of var activetabs = {}; Commented Apr 14, 2015 at 10:30

1 Answer 1

1

I think you missed couple of things in your code,

  1. return $resource from service method getDepositAccountDetails
  2. this.getDepositAccountDetails should be activetabs.getDepositAccountDetails() because you created a var for factory context.

Factory

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;
});
Sign up to request clarification or add additional context in comments.

2 Comments

sorry pankaj..still i am getting the same issue
TypeError: activetabs.getDepositAccountDetails.getDepositAccountDetailsService is not a function

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.