javascript - AngularJS dependency-injection -


i have 2 modules:

  1. foo.a
  2. foo.b

and application module:

  angular.module("foo", ["foo.a","foo.b"]) 

i have service in module foo.b say:

  angular.module("foo.b", [])    angular.module("foo.b").factory("helper",helperfn); 

which want use in 1 of controllers in foo.a.

what have done simple dependency injection:

 angular.module("foo.a", []);   angular.module("foo.a")         .controller("mycontroller",["helper",mycontrollerfn]); 

which working.

my questions

  1. how getting "helper" service module foo.b though not declared dependency module a?
  2. will break @ later stage?
  3. if correct, practice?

put factory need access in both modules in third module. have 2 original modules inject dependency third module.

angular.module("foo", ["foo.a", "foo.b"]);  angular.module("foo.a", ["foo.c"])   .controller("mycontroller", ["helper", mycontrollerfn]);  angular.module("foo.b", ["foo.c"]);  angular.module("foo.c")   .factory("helper", helperfn); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -