Search code examples
angularjsangularjs-module

AngularJS call a function defined in module from another function within the same module


Given an AngularJS module, there are two functions defined in it, functionA and functionB. How to call functionA from functionB?

app.service('myService', [

    function() {

        module = {

            functionA: function() {   ...   },

            functionB: function() {   

                // call functionA

            }

        }

        return module;
    }
]);

Solution

  • I figured it out. As the function is under the module scope (module = {) it has to be referred with the scope name i.e.

    module.functionA