-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
🚀 feature request
Relevant Package
This feature request is for @angular/core or @angular/router
Description
I have an angular Application and a separate library which contains a feature. This feature is Lazy Loaded.
In that feature I have a service which needs some configuration that is environment dependent. So this information is present in the environment.ts
files of the application.
Now I'm looking for a way to pass this environment information to my lazy loaded feature library. These services should only be accessible inside this module or its decedents.
Describe the solution you'd like
I was thinking about a similar solution as the forRoot or the forChild methods that currently exists.
@NgModule({
imports: [
RouterModule.forRoot([{
path: 'feature',
loadChildren: () => import('path/to/feature').then(module => module.FeatureModule.forChild(environment.whateverConfigSetting))
}])
]
})
export class AppModule {}
Describe alternatives you've considered
An alternative solution I currently use is that I have created an addition library with a module that implements a forRoot method. And the module.forRoot() of this library is added to the imports. of the AppModule. Disadvantage of this is that the services is now exposes to the whole application.
An other alternative solution could be to inject a AppSettings service into the service living in the feature library and fetch the environment settings of this service. Disadvantage of this solution is that for every feature library I additionally add I have a tight coupling to that service.