Normally, when you have some injectable service you wnat to use, you write something like this:
export class MyClass {
constructor(
private _myservice: MyService)
{ }
[...]
}
Unfortunally, when you extends MyClass, the child constructor, when calling super, needs to inject the same service.
export class MyClassSon extends MyClass {
constructor()
{
super(); <<<---- ERROR!!!!
}
I'm confusing. Im using SuperClass to allow sub-class to access injectable-services without inject them themself.
The best solution I found is Injector:
export class MyClass {
constructor(
injector: Injector)
{
this._myservice = injector.get(MyService);
this._fooservice = injector.get(FooService);
//others services...
}
}
export class MyClassSon extends MyClass {
constructor(injector: Injector)
{
super(injector);
//I can use any other services
}
This minimize the complexity of super-call but I'm still pissed off I need to do this trick.
Is there another way to Inject something in class without using costructor so I can leave it as clean as possible and only for specific components initialization?