Angular 4 Injecting route in the APP_INITIALIZER

前端 未结 2 1020
深忆病人
深忆病人 2021-02-14 16:52

I am trying to retrieve a data present in the url in my APP_INITIALIZER

app.module.ts

export function init(config: ConfigService, router: Router) {
    r         


        
2条回答
  •  爱一瞬间的悲伤
    2021-02-14 17:34

    config-service.ts can be rewritten as below.

    @Injectable()
    export class ConfigService
        constructor(private injector: Injector){}
    
        load(): Promise {
            const router = this.injector.get(Router);
            console.log('current url : ' + router.url);
            return new Promise(((resolve, reject) => resolve()));
        }
    }
    

    No need to inject Router as a dependency in app.module.ts.

提交回复
热议问题