gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:40:43 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com