DEV Community

Nested FormArrays in Angular ReactiveForms

Victor R. on February 07, 2019

Feb 7, 2019 Angular Reactive Forms with lots of Nesting I looked everywhere for a solution I could just copy and paste into my projec...
Collapse
 
danww profile image
Daniel Willis

Thanks, this example is great - exactly what I needed.
One small thing I discovered was that the template didn't like iterating over the controls.

I had to change this:

let player of team.get('players').controls

to this:

let player of team.get('players')['controls']

Collapse
 
sym313 profile image
Sym313 • Edited

Sadly doing all this, the .value of my form shows that player_name and player_number are not getting the data from the inputs. I had this problem with other examples. And I came here wishing to solve this issue. Any idea?

EDIT: If I copy your example without any more, works perfectly. I'll examine again my code.

Collapse
 
nawafalsuwailem profile image
Nawaf

great walkthrough. In my case, I have a command form with a list of commands (e.g., subcommands). Each subcommand can have multiple subcommands,..., etc. Essentially, all commands use the same form but each need to keep track/be aware of their parent and children. I tried different solutions but I couldn't solve it. Any thoughts? thanks

Collapse
 
charlesschneider profile image
Charles Schneider

The BEST example I have found in a long time searching! Thank you so much!

Collapse
 
thejuju profile image
Julien Gabriel

I do agree, thanks a lot for this example.

Collapse
 
sanukhandev profile image
Sanu Khan

i m not sure whats causing it i m getting this error while running i just modified the same for my code but following the same idea

No value accessor for form control with path: 'team-> 0 -> player-> 0'

Collapse
 
bilimkon profile image
Bilimkon

Thank you

Collapse
 
berik091 profile image
Berik

Thanks! Good Example

Collapse
 
gadreash profile image
gadreash • Edited

Thanks, good post!
Like others mentioned, didn't find many examples elsewhere, your code is pretty self explanatory

Collapse
 
duck5 profile image
Mr.Duckie

Any tips on showing/adding existing data to the nest form?

Collapse
 
diegoflores profile image
diegoflores

Exactly what I was looking for! Thanks for sharing!

Collapse
 
johnfewell profile image
John Fewell