创建控制器时 AngularJS 禁用表单 [英] AngularJS Disabling Forms When Controllers are Created

查看:23
本文介绍了创建控制器时 AngularJS 禁用表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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=preview

表单定义为:

<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.

更新

可以在此处找到有关尝试在 Angular 中进行此更改的一些详细信息:

Some details can be found here on trying to get this change in Angular:

https://github.com/angular/angular.js/pull/3776

推荐答案

您可以使用 ng-submit 来处理.

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=预览

Here is a quick plnkr: http://plnkr.co/edit/lwWVG0CDHSGMtMU0B8Nj?p=preview

请注意,您可以使用按钮提交,也可以在字段上按 Enter 提交.我希望这就是你一直在要求的.

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屋!

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