我正在使用一个片段来交互 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);
}
});
Run Code Online (Sandbox Code Playgroud)
this.frmCadastroImobiliaria 是我的表单组。
错误说:
Type 'AbstractControl' is missing the following properties from type 'FormControl': registerOnChange, registerOnDisabledChange, _applyFormState
Run Code Online (Sandbox Code Playgroud)
您可以使用打字稿断言(as)。
const fc: FormControl = this.frmCadastroImobiliaria.get(key) as FormControl;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6476 次 |
| 最近记录: |