NG重复提交表单,其中包含生成的字段 [英] Ng-repeat submit form with generated fields
问题描述
我有这个问题,我有一个ng-repeat,我在其中添加了一些输入字段,我想将这些输入的值提交到生成的表单中-不适用于ng-model,但是我可以通过在表单标签内输入名称.
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>
推荐答案
您应使用ng-model
&缺少form
的name
属性,因此您的ng-submit
没有着火.
You should bind the input using ng-model
& name
attribute of form
is missing which because of which your ng-submit
is not getting fire.
在将form
时,假设name="team"
那时angular确实在范围&内创建了一个新变量.添加有关表单有效性的所有与表单相关的信息;每个字段的信息.
When you add name attribute to your form
suppose name="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.
标记
<li ng-repeat="group in tournament.groups">
<form name="team" novalidate ng-submit="tournament.submit(group.team1, group.team2)">
<span>
{{ group.team1.name }}
<input type="number" name="team1" placeholder="x" ng-model="group.team1"/>
</span> - <span>
<input type="number" name="team2" placeholder="x" ng-model="group.team2"/>
{{ group.team2.name }}
</span>
<button type="submit">Save</button>
</form>
</li>
这篇关于NG重复提交表单,其中包含生成的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!