NG重复提交表单,其中包含生成的字段 [英] Ng-repeat submit form with generated fields

查看:74
本文介绍了NG重复提交表单,其中包含生成的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题,我有一个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&缺少formname属性,因此您的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆