Angular: 'AbstractControl' 缺少类型 'FormControl' 的以下属性: registerOnChange、registerOnDisabledChange、_applyFormState

标签 angular angular8

我正在使用一个片段来交互 formGroup 中的所有表单控件。该代码段一开始运行良好,但突然间 angular 开始提示

 Object.keys(this.frmCadastroImobiliaria.controls).forEach(key => {

  const fc: FormControl = this.frmCadastroImobiliaria.get(key); //here I got an error

  if(fc.touched === true) {
    fcs.push(fc);
  }

});

this.frmCadastroImobiliaria 是我的表单组。

错误说:
 Type 'AbstractControl' is missing the following properties from type 'FormControl': registerOnChange, registerOnDisabledChange, _applyFormState

最佳答案

您可以使用 typescript 断言( as )。

const fc: FormControl = this.frmCadastroImobiliaria.get(key) as FormControl; 

关于Angular: 'AbstractControl' 缺少类型 'FormControl' 的以下属性: registerOnChange、registerOnDisabledChange、_applyFormState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59569983/

相关文章:

angular - ng build 时超出调用重试次数异常

html - 如何在到期日更改字体颜色?

angular - Angular 9 的国际电话输入

javascript - 在 Angular 中显示微调器时禁用整个页面的点击

javascript - Angular2 [routerLink] 构建失败

javascript - Angular 未检测到来自 postMessage 的新窗口中 ngFor 的变化

ios - Ngbdropdown 单击事件不适用于 ios phonegap,角度 8 运行 cordova

angular - 使用 HashLocationStrategy 通过 Angular 路由处理 OAuth2 隐式重定向

typescript - index.ts 中导出的自动排序会导致应用程序崩溃

javascript - 类型错误 : Cannot read property '0' of null at SelectedDateService. ngOnInit