0

By directly I mean like this:

constructor(private injector:Injector) {
  injector.get(MyService);
}

Currently I am using this syntax on base classes that require many dependencies in order to add to the constructor arguments without having to change the derived classes. Is this a bad approach?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Craig
  • 1,648
  • 1
  • 20
  • 45

1 Answers1

0

Unfortunately it seems like there isn't a better way (best practice) to achive this. as injections only works with classes instantiated by Angular's dependency injection (DI).

Refer to this How to inject Service into class (not component)

You can use this as a workaround.

Rafi Henig
  • 5,950
  • 2
  • 16
  • 36