setupInjectionContextForLoadChildren
Workaround to emulate an injection context in the route's loadChildren resolver.
Notes
This enables asynchronous providers for routes, allowing dynamically provide injectables based on external factors.
The
used for the injection context is usually the nearest
.
This function does not transform child routes. Invoke on each route that needs an injection context.
See Also
https://github.com/angular/angular/issues/51532#issuecomment-1956138610 for the original inspiration for this workaround
Presentation
function setupInjectionContextForLoadChildren (route: Route ): Route ;
Returns
Parameters
Name | Type | Description |
---|---|---|
route |
| the route config where a injection context is needed for |
Example usage
export const APP_ROUTES: Routes = [
setupInjectionContextForLoadChildren ({
path: '',
loadChildren: async (providerLoader = inject (MyProviderLoader)) => [
{
path: '',
providers: await providerLoader.load(),
children: [
...
],
},
],
}),
];