吴之间的提交和NG-点击差异 [英] differences between ng-submit and ng-click

查看:121
本文介绍了吴之间的提交和NG-点击差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在angularjs我想知道的区别是什么之间NG-提交和NG-点击?具体来说,正反各的缺点,当你应该一个或其他?谢谢!
结果 **编辑** 结果
我看着这个有点多,但我仍然不知道的好处是采用NG-提交什么(如果有的话)?您可以使用一个NG-点击全部到位NG-提交的?这会造成什么问题呢?再次感谢!

In angularjs I'm wondering what the differences are between ng-submit and ng-click? Specifically, pros and cons of each and when should you one or the other? Thanks!
**EDIT**
I've looked in to this a bit more but I'm still wondering what (if any) the benefit is of using ng-submit? Could you use an ng-click in place of all ng-submits? Would this cause any problems? Thanks again!

推荐答案

该ngSubmit指令绑定到的在浏览器中,当一个表单提交了触发事件提交

The ngSubmit directive binds to the submit event in the browser, which is fired when a form is submitted.

从MDN:

请注意,提交仅在表单元素上发射,没有按钮或输入提交。 (表格提交,而不是按钮。)

Note that submit is fired only on the form element, not the button or submit input. (Forms are submitted, not buttons.)

所以,你可能会使用它提交用户注册表单,或者类似的东西。

So you might use it to submit a user sign-up form, or something like that.

在另一方面,该ngClick指令可以适用于任何种类的元件的

On the other hand, the ngClick directive can apply to any kind of element.

从<一个href=\"https://github.com/angular/angular.js/blob/master/src/ng/directive/ngEventDirs.js#L3\">source:

该ngClick指令允许您指定当一个自定义行为
  元素被点击。

The ngClick directive allows you to specify custom behavior when an element is clicked.

使用它,让您的用户能够与比提交表单其他一些方法你的页面互动。也许点击一个previous或下一个按钮寻呼机,或者地图什么的。

Use it to allow your user to interact with your page in some way other than submitting a form. Maybe to click on a 'previous' or 'next' pager button, or maybe a map or something.

这篇关于吴之间的提交和NG-点击差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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