refer : http://stackoverflow.com/questions/39033835/angularjs2-preload-server-configuration-before-the-application-starts ( angular initialize )

 

直接上代码 

@NgModule({
    imports: [
        StoogesModule,
        IdentityRoutingModule
    ],
    exports: [],
    declarations: [LoginComponent],
    providers: [
        IdentityService,        
        {
            provide: APP_INITIALIZER,
            useFactory: IdentityInitializeFactory, //这里不要用匿名函数, webpack 会报错
            deps: [IdentityService],
            multi: true
        },
        AdminAuthorizeGuard,
        ShopAuthorizeGuard
    ],
})
export class IdentityModule { }

factory 返回方法, 然后返回 promise.

export function IdentityInitializeFactory (identityService: IdentityService)
{
    return async () => { 
        await identityService.getUserByCookies(); 
    }
}

 

 

相关文章:

  • 2022-12-23
  • 2021-08-30
  • 2022-01-20
  • 2021-08-23
  • 2022-12-23
  • 2021-06-05
  • 2022-02-16
猜你喜欢
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2021-11-06
  • 2022-01-22
  • 2021-06-11
  • 2022-12-23
相关资源
相似解决方案