Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
feat(forms) support creating arrays with the template-driven-forms approach (NgModelArray?) #9615
I'm submitting a ... (check one with "x")
Currently we are able to do:
<div ngModelGroup="assignee"> <div class="form-group"> <label>Name</label> <input type="text" class="form-control" name="name" ngModel/> </div> <div class="form-group"> <label>E-Mail</label> <input type="text" class="form-control" name="email" ngModel/> </div> </div>
Currently there seems to be no way to create Arrays with a pure template-driven approach unless using two-way databinding.
What I would assume would be something like:
<div ngModelArray="tags"> <div *ngFor="let tag of form.value.tags; let i = index"> <div ngModelGroup="i"> <input class="form-control" name="label" ngModel minlength="3"> </div> </div> </div>
To create the structure
What is the motivation / use case for changing the behavior?
Being able to use the template-driven forms approach to create arrays without two-way databinding
Please tell us about your environment:
@kara: Just out of curiosity: Are there plans to add a directive I described above or is this no priority at the moment? I'm still not 100% sure how a suitable solution for FormArray in template-driven-forms could look like, so it would be cool to hear your thoughts about it...
@choeller Yeah, we actually wanted to build this anyway :) Unfortunately, it's a bit more complicated to build than the reactive form version because of change detection and how ngModel works. Given the time it will take and other features being higher priority, I might not get to it for a bit, but it's on the list.