ng-submit 和 ng-click 的区别 [英] differences between ng-submit and ng-click
问题描述
在 angularjs 中,我想知道 ng-submit 和 ng-click 之间有什么区别?具体来说,每个人的利弊,你应该什么时候选择另一个?谢谢!
**编辑**
我已经对此进行了更多研究,但我仍然想知道使用 ng-submit 有什么好处(如果有的话)?你能用 ng-click 代替所有的 ng-submits 吗?这会导致任何问题吗?再次感谢!
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.
来自来源:
ngClick 指令允许您指定自定义行为元素被点击.
The ngClick directive allows you to specify custom behavior when an element is clicked.
使用它允许您的用户以提交表单以外的其他方式与您的页面进行交互.也许点击上一个"或下一个"寻呼机按钮,或者地图或其他东西.
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-submit 和 ng-click 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!