How to set value on object on formbuilder inside another - Typescript

筅森魡賤 提交于 2019-12-11 02:54:58

问题


I want to access an existing formBuilder and set value of a specific object. The problem is that is not a normal formbuilder. It is a formbuilder inside another.

code:

  formBuilder.group({
      nasty: formBuilder.group({
        myobject: ['', []],
      })});

How can I set value on myobject?


回答1:


This is just a FormGroup within a FormGroup.

You could just patchValue whole form object.

this.form.patchValue({ nasty: { myobject: 'POPULATED' }})

Or you could target specific one.

this.form.get('nasty.something').patchValue('AND THIS TOO');

Here is StackBlitz with example -> https://stackblitz.com/edit/angular-3wpxsy



来源:https://stackoverflow.com/questions/54931988/how-to-set-value-on-object-on-formbuilder-inside-another-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!