typescript - Angular 2 : Error - Property 'updateValue' does not exist on type 'AbstractControl'

标签 typescript webstorm angular

我使用 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/

相关文章:

angular - 在集合 "materialDashboard"中找不到原理图 "@angular/material"

javascript - TypeError : params[item]. split 不是函数

typescript - 使用通用的扩展接口(interface)不再可分配给父级

javascript - Angular 6 : ERROR TypeError: "... is not a function" - but it is

WebStorm缓慢和卡住未知原因

javascript - 选择使用 Angular 2 显示所选值的对象

Angular - 可以有条件地应用指令吗?

javascript - TypeScript - 如何定义具有任何类型参数的函数类型

angular - WebStorm:Angular 模板类型检查

javascript - 如何在 javascript 实时模板中自动建议类/函数名称?