AngularJS禁用表单当控制器创建 [英] AngularJS Disabling Forms When Controllers are Created
问题描述
AngularJS禁用(不能提交)没有具体的动作集的形式:
AngularJS disables (cannot submit) forms that do not have a specific action set:
<form action="">
当你创建一个控制器。创建指令或工厂时,它没有这个问题。
when you create a controller. It does not have this issue when creating directive or factories.
您可以在这里普拉克看到这一点:
You can see this in a plunk here:
http://plnkr.co/edit/gWFRMKGO3FzZtOgs4VmW?p=$p$ PVIEW
形式被定义为:
<form action="" method="post">
如果您删除第6行开始,你就可以提交表单。
If you delete the starting on line 6, you will be able to submit the form.
有一个简单的解决方案是定义的动作,但我宁愿不这样做,因为这是没有必要的。
A simple solution is to define the action, but I'd rather not do this, as it is not necessary.
更新
一些细节可以在这里找到在试图让角这一变化:
Some details can be found here on trying to get this change in Angular:
https://github.com/angular/angular.js/pull/3776
推荐答案
您可以使用 NG-提交
来处理这个问题。
You can use ng-submit
to handle that.
<form ng-submit="submitForm()" method="post">
<input name="test" value="11111111" />
<button type="submit" name="submit" value="1">Send</button>
<input type="submit" name="submit2" value="Send2" />
</form>
这样的形式将正常提交,你必须实际发送你的 submitForm
函数的数据(只是一个例子名)。
That way the form will submit normally and you must actually send the data on your submitForm
function (just an example name).
下面是一个快速plnkr: http://plnkr.co/edit/lwWVG0CDHSGMtMU0B8Nj p = preVIEW
Here is a quick plnkr: http://plnkr.co/edit/lwWVG0CDHSGMtMU0B8Nj?p=preview
注意,您可以使用提交按钮和也是由pressing在字段中输入。我希望这是你一直在问什么。
Notice that you can submit using the buttons and also by pressing enter on the field. I hope that's what you've been asking for.
感谢
这篇关于AngularJS禁用表单当控制器创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!