I've created two Angular libraries, one has the other as a dependency.
the dependency needs to be configured using the forRoot method. how can i pass the configuration data from the parent library to it's dependency?
for example, let's say we have TopLevelLib
, which has OtherLib
as a dependency. OtherLib needs to be passed a configuration object using forRoot.
End user's AppModule, imports to
@NgModule({
imports: [
TopLevelLib.forRoot(someConfigData)
],
declarations: [...],
exports: [...]
})
export class AppModule { }
TopLevelLib - imported to AppModule by the end user
@NgModule({
imports: [
...
OtherLib.forRoot(*****what goes in here?*****)
],
declarations: [...],
exports: [...]
})
export class TopLevelLib {
static forRoot(config: ConfigObj): ModuleWithProviders {
return {
ngModule: SampleModule,
providers: [{ provide: SomeInjectionToken, useValue: config }]
};
}
}
OtherLib - imported by TopLevelLib
@NgModule({
imports: [...],
declarations: [...],
exports: [...]
})
export class OtherLib {
static forRoot(config: ConfigObj): ModuleWithProviders {
return {
ngModule: SampleModule,
providers: [{ provide: SomeInjectionToken, useValue: config }]
};
}
}
What i need is to pass the configuration object instance from TopLevelLib to OtherLib. So that when the end user configures TopLevelLib using forRoot, OtherLib will be configured with the same data.
Any ideas on how to implement this?