I have this issue, where i have a ng-repeat where i add some input fields and i want to submit the value of these inputs to the generated form - dosn't work with ng-model, but can i get by input name inside the form tag.
<li ng-repeat="group in tournament.groups">
<form novalidate ng-submit="tournament.submit(group.team1, group.team2)">
<span>
{{ group.team1.name }}
<input type="number" name="team1" placeholder="x">
</span> - <span>
<input type="number" name="team2" placeholder="x">
{{ group.team2.name }}
</span>
<button type="submit">Save</button>
</form>
</li>
In the approach you have used you will be having multiple forms. I would suggest you to have only one form and iterate inside the form as follows :
And have the ng-model updated for each and every group accordingly using '$index' (as ng-model="team{{$index}}")
I guess this should do the trick.
Use ng-model:
View:
in controller:
You will get your value. Try once my code.
You should bind the input using
ng-model
&name
attribute ofform
is missing which because of which yourng-submit
is not getting fire.When you add name attribute to your
form
supposename="team"
at that time angular does create a new variable inside scope & add all the form related information about the validity of form & the information of each field.Markup