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.

2
  • Are you using Reactive form or template driven form? Commented Sep 3, 2018 at 13:06
  • I'm using reactive form Commented Sep 3, 2018 at 13:49

2 Answers 2

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')
Sign up to request clarification or add additional context in comments.

Comments

2

use form.get('controlName')

this.form.get('address').get('pincode').setValue(selected.id);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.