Before bootstraping my angular app I need to perform an async operation which returns some context for the application. Before starting, I need to init some 3rd party repository with these returned data, and then I'd like to inject this repository into on of my app's services. I'm looking for a proper, clean way of doing it, because the one that I currently have looks a bit hacky for me.
app.module.ts content:
let repo; //this is what i'd like to avoid
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ReactiveFormsModule
],
providers: [
{
provide: SomeService, useFactory: () => new SomeService(repo)
}
],
entryComponents: [AppComponent]
})
export class AppModule implements DoBootstrap {
ngDoBootstrap(app: ApplicationRef) {
//some async operation which returns context data
setTimeout((data) => {
repo = Some3rdPartyDatabaseSDK.init(data.token, data.repoConfig)
app.bootstrap(AppComponent);
}, 3000);
}
}
Can it be done better?
APP_INITIALIZERAPP_INITIALIZERthen as suggested by @yurzui.