我正在使用一个片段来交互 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/