您可以在此处找到演示该问题的 Plunker:Plunker
我想在 AngularJS 中使用嵌套表单。为此,似乎 ng-form
是可行的方法,我尝试了以下方法:
<form novalidate ng-submit="ctrl.form1()">
<button type=submit>Form1</button>
<ng-form novalidate ng-submit="ctrl.form2()">
<button type=submit>Form2</button>
</ng-form>
</form>
虽然我希望内部提交执行内部表单的提交操作,但每次我单击任一按钮时都会调用方法 form1()
。
为什么会这样,我怎样才能达到预期的结果?
最佳答案
You can use one of the following two ways to specify what javascript method should be called when a form is submitted: * ngSubmit directive on the form element * ngClick directive on the first button or input field of type submit (input[type=submit])
<form novalidate>
<button type=submit ng-click="ctrl.form1()">Form1</button>
<ng-form novalidate >
<button type=submit ng-click="ctrl.form2()">Form2</button>
</ng-form>
</form>
参见工作插件 here
关于javascript - AngularJS 中的嵌套表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38069746/