K
K
Konstantin2020-11-23 16:00:35
Angular
Konstantin, 2020-11-23 16:00:35

How to load data before starting the application?

I use this in a lazy load module:

{
            provide: APP_INITIALIZER,
            useFactory: appInit,
            deps: [DocumentsSettings],
            multi: true,
        },

export function appInit(settings: DocumentsSettings) {
    return () => settings.init();
}

@Injectable()
export class DocumentsSettings implements Settings {
    private readonly url = `${environment.apiUrl}/documents`;
    
    public init() {
        return new Promise((resolve, reject) => {
            alert();
            resolve(true);
        });
    }
}


But there is no reaction, alert()it is not displayed.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question