I want to use a module that needs to provide a config object to its forRoot(), but I get this config object via an HTTP request, so it returns a promise (or an Observable)
my-module.module.ts
@NgModule({
imports:[{
someModule.forRoot({ /* config */})
}]
})
export class MyModule{}
I tried to provide this config via useFactory
@NgModule({
imports:[{
someModule.forRoot({ /* config */})
}],
providers:[{provide: 'someModuleConfigs', useFactory: ()=>Promise.resolve({x: 1})}]
})
export class MyModule{}
this causes an error because .forRoot()
requires an object with some required properties, but in this solution, I pass just an empty object
also, I tried to use the token APP_INITIALIZER
to load this object when the app initializes
but again, I pass an empty object to .forRoot()
which causes the same error
The question is:
how to pass a configs object to .forRoot()
from a Promise?