Reputation: 397
If I want to copy a formgroup
to other, what is the best option?
For example, if message is my formgroup
which has widgets array that needs to be copied to the pageForm fromgroup
which has similar structure as of message.
I tried:
(<FormArray>this.pageForm.get('widgets')).push(<FormArray>this.message.get('widgets'))
Upvotes: 3
Views: 5787
Reputation: 13963
If you only want to copy the data, you can use patchValue
:
this.form.targetGroup.patchValue(this.form.sourceGroup.value);
Here is the angular doc for FormGroup and patchValue.
Upvotes: 3