angular.io
angular.io copied to clipboard
To improve the router guide
angular/angular#12995 Resolver can inject custom providers from application root only.
This is not true and is already stated in the docs
Guards and the service providers they require must be provided at the module-level. This allows the Router access to retrieve these services from the Injector during the navigation process. The same rule applies for feature modules loaded asynchronously.
@brandonroberts What is not true? Module-level providers are gathered in application root injector. Every resolver that router instantiates along the path inherits from application root or how you said module-level.
We were talking in (angular/angular#12995) about case where I have supposed that resolver can inject services from the most closer component injector.
Let say we have this route:
Root(Service("Root")) -> Parent(Service("Parent"))->Child(Service)
->Resolver(Service)
In `Child` we have Service("Parent")
In 'Resolver' we have Service("Root")
Resolver's injector doesn't see Service("Parent") it sees only Service("Root")
Module-level providers are gathered in the application root injector only if they're imported into the root module. The case is not the same for lazy loaded modules. Component injectors can't be used because all guards and resolvers are run before any components are rendered. This is why resolve and guard providers must be used at the module level so the module-level injector can retreive them.
@brandonroberts yes, you try to explain me for the second time) why resolver can't inject service from closest component. @DzmitryShylovich ask me to create issue in this repo to express this case in documentation.
Guards and the service providers they require must be provided at the module-level. This allows the Router access to retrieve these services from the Injector during the navigation process. The same rule applies for feature modules loaded
This text is not about my case.
You can't conclude from it from what places resolver can get services.
I see. I'll add an explicit mention to the guide about the same requirement for resolvers .
ok @brandonroberts