2

When a component extends another component and the base component has dependencies, I declare them in the child component and call super() with the dependencies.

This becomes quite troublesome if the component needs 2 dependencies (service1, service2) and the base component needs 3 other dependencies (service3, service4, service5).

I'll have to do it like this

export class ChildComponent extends ParentComponent {
  constructor(service1: ServiceType1,
              service2: ServiceType2,
              service3: ServiceType3,
              service4: ServiceType4,
              service5: ServiceType5) {
    super(service3,service4,service5);
  }
}

Question

Is there a way to do this where I won't have to declare every single dependency my parent component needs?

I was considering maybe injecting an Injector and ask the service to provide it's own dependencies through the injector - is that possible?

Danyg
  • 73
  • 4
  • Possible duplicate of [Inheritance and dependency injection](https://stackoverflow.com/questions/39038791/inheritance-and-dependency-injection) – jonrsharpe May 01 '18 at 09:54
  • I don't believe so, that's exactly how injection works. If you're not declaring a dependency, it's not a dependency. You could wrap it all up in a single service, but thats a bit of a hack – Malcor May 01 '18 at 09:54

0 Answers0