How to provide a valye from an async function? For example, a fetch result from an URL? I've tried the following:
const TOKEN = new InjectionToken<ConfObject>('confObject');
async function asyncFunction() {
const resp = await fetch(`<url>`);
const config = await resp.json() as MyObject;
return ({a: config.a, b: config.b, c: environment.value} as ConfObject)
}
const ConfObjectFactory = () => {
return () => asyncFunction();
}
bootstrapApplication(AppComponent, {
providers: [
{
provide: TOKEN,
useFactory: ConfObjectFacctory()
},
]);
When I do that, inject(TOKEN) returns a ZonedAwarePromise (a promise, anyway...). But other places expect to get injected an instance of ConfObject.
I know I'm missing something, but I can't find what... Any help will be greately appreciated.