Angular - APP_INITIALIZER - Promise vs Observable
Angular 12 added support for Observable
s, so this should no longer be an issue if you're using Angular 12 or newer.
The reason load_one
works and load_two
doesn't is that Angular 11 and older waits only for Promise
s; not Observable
s.
Here's the source:
if (this.appInits) { for (let i = 0; i < this.appInits.length; i++) { const initResult = this.appInits[i](); if (isPromise(initResult)) { asyncInitPromises.push(initResult); } }}
Where isPromise
is defined like this:
export function isPromise<T = any>(obj: any): obj is Promise<T> { // allow any Promise/A+ compliant thenable. // It's up to the caller to ensure that obj.then conforms to the spec return !!obj && typeof obj.then === 'function';}