I need to get the config using a factory that will be resolved during the APP INITIALIZATION (using the APP_INITIALIZER provider).
export function loadConfig(): () => Promise<Config> {
// return promised config
}
That is provided using the AppModule:
providers: [{
provide: APP_INITIALIZER,
useFactory: loadConfig,
deps: [HttpClient, ConfigService],
multi: true
}]
Then I need to use that configuration data in inject something inside another InjectionToken, but if I provide the specific injectiontoken using the config provided during the app initialization, that process is executed before the APP_INITIALIZER execution.
export const FORMATS = new InjectionToken<Formats>("formats")
export assignFormat(configService: ConfigService) {
return configService.getFormats(); // Needs to execute after APP_INITIALIZER, not before
}
providers: [{
provide: APP_INITIALIZER,
useFactory: loadConfig,
deps: [HttpClient, ConfigService],
multi: true
}, {
provide: FORMATS,
useFactory: assignFormat,
deps: [ConfigService]
}]
@Injectable({ providedIn: "root" })
export class ConfigService {
constructor() {}
getFormats() {}
}
How can I do to provide the injection token after the APP initialization?