javascript - AngularJS dependency-injection -
i have 2 modules:
foo.afoo.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
- how getting "helper" service module
foo.bthough not declared dependency module a? - will break @ later stage?
- 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
Post a Comment