I have a decorated modal service that basically logs some information before opening a new window. Think...
export class OriginalModalClass {
public open(component: any): ModalInstance {
// Interesting stuff here
}
}
@Injectable({ providedIn: 'root' })
export class DecoratedModalClass extends OriginalModalClass {
constructor(private logger: Logger) {}
public open(component: any): ModalInstance {
logger.log(component.name);
super.open(component);
}
}
This app is not well optimized and does not load any modules lazily, and so every component service, etc is in one large module. This logging seems to always work when opening the first window but if that same service is a dependency of the first modal which opens another modal window the service dependency is not substituted and so nothing is logged. Do I need to explicitly specify it as a provider for these cases? I originally looked into using forRoot()
but this seems to be a solution designed for lazy loaded modules which we currently don't use.
@NgModule({
exports: [...],
imports: [...],
providers: [
{ provide: OriginalModalClass, useFactory: (decoratedModalClass) => decoratedModalClass, deps: [DecoratedModalClass] }
]
}) AppModule {}
Aucun commentaire:
Enregistrer un commentaire