I have a service in Angular that inherits from an abstract class and implements an abstract method.
@Injectable({
providedIn: 'root',
})
export class ClassB extends ClassA {
constructor(
private service : ExampleService) {
super();
}
abstractMethod() {
//this.service returns undefined here
}
}
export abstract class ClassA {
abstractMethod();
otherMethod() {
this.abstractMethod();
}
}
However, in the constructor of ClasseB I need to inject a service that will be used within the abstract method.
The abstract method is executed inside "otherMethod ()" in the Abstract class, as the abstractMethod () method has no implementation in the Parent class, it will call the implementation inside the child class, however, at that moment it returns undefined.
How do I get to use a service instance within the abstractMethod ()?
Basically, what I need is to be able to get a service instance inside "abstractMethod ()", it is currently returning undefined.