Angular. Router DI not working when using APP_INITIALIZER

懵懂的女人 提交于 2019-12-04 08:30:29

This works works in anguler 4

import { APP_INITIALIZER, Provider, Injector } from '@angular/core';

export function appInitializerFactory(
    injector: Injector
): () => Promise<any> {
    return () => {
        return new Promise<any>((resolve, reject) => {
            setTimeout(() => {
                const router = injector.get(Router);
                // do stuff
                resolve(this.config);
            });
        });
    }
}

export const appInitializerProvider: Provider = {
    provide: APP_INITIALIZER,
    useFactory: appInitializerFactory,
    deps: [
        Injector
    ],
    multi: true
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!