Estoy desarrollando un módulo que admite Root y Child. Siempre que este módulo se importe con forRoot, forChild se deben llamar algunos métodos de un servicio personalizado. Funciona bien para forRoot ya que uso APP_INITIALIZER , pero ya no se llama a la fábrica en forChild de un módulo con carga diferida. ¿Cómo puedo ejecutar los métodos que tengo en mi fábrica en el forChild para que también funcione con módulos con carga diferida? ¿Hay algún tipo de equivalente de APP_INITIALIZER para módulos con carga diferida o una solución alternativa?
export const TRANSLATION_CONFIGURATION = new InjectionToken<TranslationConfiguration<any>>(''); function initializeAppFactory(config: TranslationConfiguration<any> & { language: Language }, locutus: LocutusService): () => void { return () => { if (config.language) { locutus.registerRoot(config); return; } locutus.registerChild({ scope: config.scope, loaders: config.loaders }); }; } @NgModule({ declarations: [ NgxLocutusComponent, LocutusDirective, LocutussPipe ], imports: [ CommonModule ], exports: [ NgxLocutusComponent, LocutusDirective, LocutussPipe ] }) export class LocutusModule { static forRoot<T>(config: TranslationConfiguration<T> & { language: Language }): ModuleWithProviders<LocutusModule> { return { ngModule: LocutusModule, providers: [ { provide: TRANSLATION_CONFIGURATION, useValue: config, }, { provide: APP_INITIALIZER, useFactory: initializeAppFactory, deps: [ TRANSLATION_CONFIGURATION, LocutusService ], multi: true }, ] }; } static forChild<T>(config: TranslationConfiguration<T>): ModuleWithProviders<LocutusModule> { return { ngModule: LocutusModule, providers: [ { provide: TRANSLATION_CONFIGURATION, useValue: config, }, { provide: APP_INITIALIZER, useFactory: initializeAppFactory, deps: [ TRANSLATION_CONFIGURATION, LocutusService ], multi: true }, ] }; } }