为什么我们在angularjs中使用form或ng-submit? [英] Why do we use form or ng-submit in angularjs?
问题描述
我计划有一个angularjs应用程序.我们将使用Web Api服务进行CRUD操作.我可以从ng-click指令中调用这些控制器功能(我的意思是没有提交)
I am planning to have an angularjs application. We will be doing the CRUD operation using Web Api service. And these controller functions I can call from ng-click directive (I mean with out a submit)
AngularJs <-> WebApi <-> Sql Serevr
=>这是我们的堆栈.
AngularJs <-> WebApi <-> Sql Serevr
=> This is our stack.
我们需要致电Web服务器(以获取文件.例如:图片).
We need get call to web server (to fetch files. Ex: images).
但是我想知道,在这种情况下,我们是否需要对Web服务器进行后期操作?
But I am wondering, will we ever need a post operation into webserver in our case?
此外,我们是否需要表单,ng-form,submit,ng-submit?
Also, do we ever need a form,ng-form,submit,ng-submit - in our case?
任何帮助都将得到感谢,谢谢!
Any help would be apprecicated, Thanks!
推荐答案
除了在代码中提交使用<form>
标记外,还有很多原因.首先,将验证结果直接连接到表单对象中.如果您没有该表单,则不会获得该功能.
There are number of reasons outside of just submitting to use a <form>
tag in your code. For one, angular wires up validation results right into the form object. If you didn't have the form, you wouldn't get that functionality.
我建议您看一下Angular Form文档底部的示例,以了解为什么要使用Form.如果清除示例中的文本框,则可以看到form.$ valid和form.$ error如何更改.
I'd suggest taking a look at the example at the bottom of the Angular Form documentation to see why you may want to use the Form. You can see how the form.$valid and form.$error change if you clear out the textbox in the example.
https://docs.angularjs.org/api/ng/directive/form
关于提交,ngSubmit将阻止通常用于发布服务器的表单的默认操作.与现有的验证属性类似,还有一个form.$submitted
属性,当使用ng-submit提交表单时,该属性将更新为true.在ng-click上不会发生这种情况.
Regarding submitting, ngSubmit will prevent the default action of a form which is usually posting the server. Similar to the validation properties that exist, there is also a form.$submitted
property that will be updated to true when the form is submitted with an ng-submit. This will not happen on an ng-click.
https://docs.angularjs.org/api/ng/directive/ngSubmit
这篇关于为什么我们在angularjs中使用form或ng-submit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!