Angularjs 在表单中提交表单?
我想在表单中发送表单,但当我在表单中提交表单时,所有表单都已提交。 甚至有可能做到这一点吗Angularjs 在表单中提交表单?,angularjs,forms,Angularjs,Forms,我想在表单中发送表单,但当我在表单中提交表单时,所有表单都已提交。 甚至有可能做到这一点吗 <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="he
<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>
不,嵌套表单不起作用
在Angular中,可以嵌套窗体。这意味着外部形式是
当所有子窗体都有效时有效。但是,浏览器
不允许元素嵌套,因此Angular提供
ngForm指令,其行为与相同,但可以
嵌套的。这允许您拥有嵌套表单,这非常有用
在动态更新的表单中使用角度验证指令时
使用ngRepeat指令生成
但不幸的是,您不能使用ng submit
表单,它将在单击任何内部表单时调用父ng submit
方法
解决方法是不要对内部嵌套的发件人使用ng submit
指令。您应该使用ng单击按钮上的
,并将按钮类型从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>
最好不要将表单嵌套在表单中。您可以尝试将表单标记用于“提交”按钮。问题是,这两种情况都调用了相同的事件处理程序