javascript - Accessing factory defined in another module in angularjs -


can call factory functions defined in 1 module module? if so, how?

let's first module defined in moduleone.js file as:

var mymodule = angular.module('myservicemoduleone', []); mymodule.factory('notify', function () {     return {         samplefun: function () {             // code call samplefuntwo()         },     }; }); 

and second module in moduletwo.js as:

var mymoduletwo = angular.module('myservicemoduletwo', []); mymoduletwo.factory('notifytwo', function () {     return {         samplefuntwo: function () {             // code         },     }; }); 

how call samplefuntwo() samplefun()?

thanks.

you need inject myservicemoduletwo myservicemodule:

var mymoduletwo= angular.module('myservicemoduletwo',[]); var mymodule= angular.module('myservicemoduleone', ['myservicemoduletwo']); 

then inject notifytwo notify:

mymodule.factory('notify', function(notifytwo) {     return {         samplefun: function() {             notifytwo.samplefuntwo();         }           }; });   mymoduletwo.factory('notifytwo', function() {     return {         samplefuntwo: function() {             alert('from notify two');         }         }; });  

and code on plunker


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -