Lakshay Bansal
Lakshay Bansal

Reputation: 397

How to copy one formGroup to the other in Angular?

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

Answers (1)

jo_va
jo_va

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

Related Questions