我使用 FormBuilder 创建了一个 ControlGroup theForm
。
当我尝试像这样更新控件的值时
this.theForm.find('MainImageId').updateValue(id, true, true);
它工作正常,但 WebStorm 显示错误提示
错误:(148, 24) TS2339:类型“AbstractControl”上不存在属性“updateValue”。
我做错了什么?为什么它有效?
最佳答案
根据 Typescript casting object's property我想这应该可以解决它
find
现在是 get
(>=RC.5)
(<Control> this.theForm.find('MainImageId')) .updateValue( id, {onlySelf:true, emitEvent:true});
// (<Control> this.theForm.find('MainImageId')) .updateValue( id, {onlySelf:true, emitEvent:true});
编辑:可选参数在第二个参数中作为对象提供。
关于typescript - Angular 2 : Error - Property 'updateValue' does not exist on type 'AbstractControl' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34669849/