Let's say: I use a module called constants
.
angular.module("constants", [])
.constant("A", 10);
I want to use this constant A
in another module:
angular.module("moduleThatUseConstants", ["constants"])
.service("B", ["A", Services.B]); // here I use A
That works ! But what if I already have another constant (or controller etc) called A
?
angular.module("moduleThatUseConstants", ["constants"])
.service("A", [Services.A]);
.service("B", ["A", Services.B]); // ???
Question: How to specify that A
comes from the module constants
? I tried:
.service("B", ["constants.A", Services.B]);
But that doesn't work $injector:unpr Unknown Provider "constants.A"
You cannot achieve this. The later one with the same name will always be resolved. This is one of the shortcomings of DI in Angular 1.x. I expect to see a solution to this in the Angular 2 DI.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.