小编Pur*_*ang的帖子

无法将抽象构造函数类型分配给非抽象构造函数类型

我试图以角度制作一个抽象组件,但出现以下错误:

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 …

abstract-class typescript angular

9
推荐指数
1
解决办法
5822
查看次数

标签 统计

abstract-class ×1

angular ×1

typescript ×1