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
Post a Comment