A_Singh A_Singh - 11 months ago 85
TypeScript Question

Angular2: Error - Property 'updateValue' does not exist on type 'AbstractControl'

I've created a ControlGroup

using FormBuilder.

When I tried to update value of a control like this

this.theForm.find('MainImageId').updateValue( id, true, true);

It worked fine but WebStorm shows an error saying

Error:(148, 24) TS2339: Property 'updateValue' does not exist on type 'AbstractControl'.

What am I doing wrong? and why does it work?

Answer Source

According to Typescript casting object's property I guess this should fix it

find is now 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});

Edit: Optional parameters are supplied as an Object in second parameter.