Issue
I'm trying to make an abstract component in angular but am getting 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
~~~~~~~~~~~~~~~~~~~~~
This is my 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 seems like Angular has problems with the constructor but I need the constructor for the service so I cannot delete it. Is there any way that I can use abstract classes with a constructor/injecting services?
Solution
Solution is just not adding the abstract component to app.modules. I can still use it as abstract Component and I don't get any errors.
Answered By - Purple Gang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.