2

I'm creating a dynamic form with Angular 2 (or 4) with a form array (rooms) nesting a form array (children).

The children array won't bind controls and values in .value form property even if they are added to it.

Here the plunkr: https://embed.plnkr.co/DjtLLt0vS0qmmvgqKhN8/

What I miss?

1 Answer 1

3

You have one simple error, remove the last controls from your addChild():

addChild(i: number) {
    const control = 
       //remove the last 'controls'
       this.searchform.controls.rooms).controls[i]).controls["children"].controls;
    control.push(this.initAge());
}

and instead:

addChild(i: number) {
    const control =
      this.searchform.controls.rooms).controls[i]).controls["children"];
    control.push(this.initAge());
}

Here's your forked plunker: https://plnkr.co/edit/SmnjBroGHufori1PWNSR?p=preview

Sign up to request clarification or add additional context in comments.

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.