角提交表格内的形式? [英] Angular submit form inside form?

查看:75
本文介绍了角提交表格内的形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表单内发送表单,但是当我在表单内部提交表单时,所有表单现在都已提交. 甚至有可能这样做吗?

I wanna send a form inside a form, but when I submit the form-inside-the-form, all the forms are submitted now. Is it even possible to do this?

<form name="add_foobar_form" novalidate ng-submit="addFoobar(foobar)">

    <form name="send_contact_form" novalidate ng-submit="sendContact(hello)">
        <input type="text" ng-model="hello.bye">
        <input type="submit" value="sendmall">
    </form>

    <input type="text" ng-model="foobar.go">
    <input type="submit" value="sendall">

</form>

推荐答案

可以吗有嵌套表格吗? 根本不行,嵌套表格不起作用.

Can you have nested forms? Simply no, Nested form won't work.

文档说

Docs Says

在Angular中,表单可以嵌套.这意味着外部形式是 当所有子窗体都有效时也有效.但是,浏览器 不允许元素嵌套,因此Angular提供了 ngForm指令的行为与之相同,但可以是 嵌套这使您可以使用嵌套表格,这非常有用 以动态形式使用Angular验证指令时 使用ngRepeat指令生成的

In Angular, forms can be nested. This means that the outer form is valid when all of the child forms are valid as well. However, browsers do not allow nesting of elements, so Angular provides the ngForm directive which behaves identically to but can be nested. This allows you to have nested forms, which is very useful when using Angular validation directives in forms that are dynamically generated using the ngRepeat directive

但是很遗憾,您不能使用ng-submit表单,该表单将在单击任何内部表单时调用父ng-submit方法.

But unfortunately you could not use the ng-submit form, that will call the parent ng-submit method on click of any inner form.

> 示例Plunkr

为此的解决方法是,不要对内部嵌套的源使用ng-submit指令.您应该在按钮上使用ng-click,并将按钮的类型从submit更改为button.

Workaround for this would be don't use ng-submit directive for the inner nested from. You should use ng-click on button and change type of button to button from submit.

标记

<form name="add_foobar_form" novalidate ng-submit="addFoobar('foobar')">
    <ng-form name="send_contact_form" novalidate>
      <input type="text" ng-model="hello.bye">
      <input type="button" value="sendmall" ng-click="sendContact('hello')">
    </ng-form>

    <input type="text" ng-model="foobar.go">
    <input type="submit" value="sendall">
</form>

> 解决方法Plunkr

这篇关于角提交表格内的形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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