I am attempting to create an abstract component in Angular, but I am encountering the following error:
Error: src/app/app.module.ts:191:5 - error TS2322: Type 'typeof AbstractFormComponent' is not assignable to type 'any[] | Type<any>'.
Type 'typeof AbstractFormComponent' is not assignable to type 'Type<any>'.
Cannot assign an abstract constructor type to a non-abstract constructor type.
191 AbstractFormComponent
~~~~~~~~~~~~~~~~~~~~~
Here is my implementation of the abstract Component:
@Component({
selector: 'app-abstract-form',
templateUrl: './abstract-form.component.html',
styleUrls: ['./abstract-form.component.scss']
})
export abstract class AbstractFormComponent implements OnInit, AfterViewInit {
protected constructor(protected formService: FormService) {
}
protected abstract getForms(): AbstractControl[];
ngOnInit(): void {
}
ngAfterViewInit(): void {
this.getForms().forEach(f => this.formService.addForm(f));
}
}
It appears that Angular is having issues with the constructor, but since I require it for the service injection, deleting it is not an option. Is there a way to utilize abstract classes while still including a constructor and injecting services?