Why do we use form or ng-submit in angularjs?

后端 未结 2 485
日久生厌
日久生厌 2021-01-25 00:09

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 m

相关标签:
2条回答
  • 2021-01-25 00:29

    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.

    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

    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

    0 讨论(0)
  • 2021-01-25 00:55

    Not much different,but ng-submit would be prevent by input[required] etc. ng-click is unlimited

    0 讨论(0)
提交回复
热议问题