Monday 5 October 2020

APP_INITIALIZER factory is not running at all when configured within Angular library

Example Code in library:

export function appSettingsLoader(): () => Promise<unknown> {
  console.log('i should run first')
  const func = function () { return Promise.Resolve()) };
  return func;
}

@NgModule({
  imports: [
    MsalModule
  ]
})
export class MsalAuthenticationModule {
  public static forRoot(options: {
    config: Type<IMsalConfigurationService>
  }): ModuleWithProviders {
    return {
      ngModule: MsalAuthenticationModule,
      providers: [
        {
          provide: APP_INITIALIZER,
          useFactory: appSettingsLoader,
          deps: [],
          multi: true
        }
      ]
    };
  }
}

Code in app module:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    MsalAuthenticationModule.forRoot({ config: Config })
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}

At no point will I ever see my console.log.



from APP_INITIALIZER factory is not running at all when configured within Angular library

No comments:

Post a Comment