0

So I have a nested form like this:

form
    - address
        - city
        - state
        - pincode
    - name
    - phone

now I want to set the value of pincode programatically. How do I set it? I have checked it for the non nested form and found it here: But can't seem to find it for nested forms.

I have tried using dot notation for finding controls.

gndps
  • 461
  • 3
  • 13

2 Answers2

2

use form.get('controlName')

this.form.get('address').get('pincode').setValue(selected.id);
Krishna Rathore
  • 9,389
  • 5
  • 24
  • 48
2

Try something like this:

Refer Demo to understand form array

DEMO

Use index to get controls of FormArray.

form.controls.address.controls[i].controls.pincode.setValue('your_pin')
Akj
  • 7,038
  • 3
  • 28
  • 40