0

I have a factory, how do i call 'getAccountDetails' service inside getAccountInformation() function.

I tried in the following way, but not working.

AccountService.getAccountDetails.getAccountDetailsService

factory

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

2 Answers 2

1

I suggest you define your code dependencies out of the returned provider:

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){
                 ...
            })
        }      
    };
}]);

Or, inside an object, you can also use this to refer to the current object, instead of using AccountService.getAccountDetails, you should use 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){
                 ...
            })
        }      
    };
}]);

Plus, be careful, because your naming convention is confusing (getAccountDetails is not a function, since you don't call it with (), but it is named "get", getAccountServices is first defined as an object, but the same name is used later for a funtion...), especially if you want an accurate answer ;)

Sign up to request clarification or add additional context in comments.

Comments

0

This should work, havent tested it though.

tellerApp.factory('AccountService',['$resource', function ($resource) {
    var AccountService = {
        getAccountDetails: $resource(XXX, {}, {
            getAccountDetailsService: {}
        }),
        getAccountInformation: function($scope, number, transaction, index){
            AccountService.getAccountDetails.getAccountDetailsService({number : number}).$promise.then(function(response){
            }
        };       

    }
    return AccountService
}]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.