You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide an official way to access the module/injector for a route #25630
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:
Current behavior
When lazy-loading modules, the router faces the problem of how to inject providers that are registered in the child module from a root service, since providers in lazy-loaded modules are not added to the root injector.
The implementation solves this problem by keeping a reference to the lazy-loaded module in the router config, which it can use to lookup the child module's injector. However, this capability is kept internal to the router, which prevents apps that have the same requirement from using it.
Now, consider an app that includes its own DI tokens on lazy-loaded route definitions. E.g.:
If ProjectBreadcrumbProvider is registered in the lazy-loaded module, then a global BreadcrumbService in the root module cannot inject it using the root injector. It needs the injector associated with the current route instead, but there is no official way to get hold of it.
Expected behavior
The Router should provide an official way to access the module/injector for a given ActivatedRoute. I would suggest running the same closestLoadedConfig() logic eagerly and including the resulting module as a module property on each ActivatedRouteSnapshot instance.
What is the motivation / use case for changing the behavior?
Apps currently have two options:
Replicate the logic from closestLoadedConfig() and rely on the internal _loadedConfig property. But relying on private APIs is not a good idea, as these could change or be removed in a later version.
Register these providers in the root scope, rather than the lazy module. But this bloats the root module and defeats the purpose of lazy-loading.
Neither of these is preferable. An official way to get the module/injector for a given route would solve the problem.
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
Activity
angular-robot commentedon Jun 4, 2021
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.
Find more details about Angular's feature request process in our documentation.
angular-robot commentedon Jun 25, 2021
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
atscott commentedon Jul 24, 2021
Closing as duplicate of #24069
angular-automatic-lock-bot commentedon Aug 24, 2021
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.