I've got the BaseComponent
which got some dependencies injected. The first dependency EntityService
is correct and necessary.
ButAnyOtherService
is only used inside the abstract BaseComponent
. Instead of injecting it inside the ChildComponent
, where it is not used, I'd like to inject it only inside BaseComonent
.
Why do I have to push it through the ChildComponent
towards the BaseComponent
? The best solution would be to encapsulate it inside the BaseComponent
.
base.component.ts
export abstract class BaseComponent {
constructor(
protected entityService: EntityService,
// protected anyOtherService: AnyOtherService // @todo add this
) {
}
}
child.component.ts
@Component()
export class ChildComponent extends BaseComponent {
constructor(
private firstService: FirstService,
private secondService: SecondService,
protected anyOtherService: AnyOtherService // @todo remove this
) {
super(
firstService,
anyOtherService // @todo remove this
);
}
}