The order of providers in Angular Dependency Injection matters.
If you provide a custom implementation "before" the default implementation is provided, then the default implementation will take precedence. The "last provided" wins. Angular traverses the tree of modules, grabs all providers and flatten them all to one list. In case of conflicts, then the last provided in the list wins.
Angular traverses modules tree, starting from the root module (often named AppModule)
:
- first are providers from imported modules (depth-first), e.g.
imports: [SomeModule, ...]
- then providers from static methods of imported modules, e.g.
imports: [SomeModule.forRootOrWhateverMethodName(), ...]
- then providers from the currently analyzed module
providers: [...]
Top comments (1)
Not understanding at all. If you can put more examples and use cases, then will be better.