angular icon indicating copy to clipboard operation
angular copied to clipboard

MergeInjector breaks normal Angular DI priority

Open msgoloborodov opened this issue 2 years ago • 4 comments

https://github.com/ui-router/angular/blob/34c0efcc04d1ccb3384b06dd362451d3ff40a62d/src/directives/uiView.ts#L326

msgoloborodov avatar Jan 19 '23 17:01 msgoloborodov

https://angular.io/guide/hierarchical-dependency-injection#resolution-rules Angular tries to find dependency in ElementInjector tree, if Angular doesn't find the provider in any ElementInjector hierarchies, it goes back to the element where the request originated and looks in the ModuleInjector hierarchy. But UIView creates component with custom injector MergeInjector which firstly search token in ModuleInjector and then in ElementInjector. For example, it will return service provided in root ModuleInjector, but it must return service provided in parent component or in lazy module (child module). I think it should first look in all parents element injectors and only then in moduleInjector.

msgoloborodov avatar Jan 19 '23 18:01 msgoloborodov

PR to fix this issue: https://github.com/ui-router/angular/pull/978.

msgoloborodov avatar Jan 23 '23 15:01 msgoloborodov

When is this an issue?

wawyed avatar Aug 04 '23 10:08 wawyed