问题
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