Pur*_*ang 9 abstract-class typescript angular
我试图以角度制作一个抽象组件,但出现以下错误:
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
~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
这是我的抽象组件:
@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));
}
}
Run Code Online (Sandbox Code Playgroud)
Angular 的构造函数似乎有问题,但我需要该服务的构造函数,所以我无法删除它。有什么方法可以将抽象类与构造函数/注入服务一起使用?
| 归档时间: |
|
| 查看次数: |
5822 次 |
| 最近记录: |