I have a service declared in my module.ts file to have an application-wide scope. The way to access the instance of this service is to declare it as part of the constructor for the component class, like so, and the framework automatically wires it up:
export class ComponentBase implements OnInit {
constructor(private myService: MyService) { }
}
My component class is one of several similar components, so they all share a common base class, and this constructor is on the base. I discovered that base constructors are not automatically required, so it is possible that a derived class ends up without a constructor (and without the dependency).
So, is there another, more foolproof way to do it in the base class?
protectedin the base class constructor.protectedorprivate, it will not exist so long as the derived class fails to call thesuper(...)constructor.super(...)is not called?console.log. I originally thought otherwise, which is why the bug took a long time for me to track down.HelloComponentis derived from theBaseComponent.