Form in AngularJS
AngularJS complements the form of filling and validation features. You can use ng-click directive to handle the event by clicking on the button and using the flags $ dirty and $ invalid to make it effective. Use novalidate with the form declaration to disable the valicate feature of the form. The control section of the form uses an effective set of AngularJS events.
AngularJS complements the form of filling and validation features. You can use ng-click directive to handle the event by clicking on the button and using the flags $ dirty and $ invalid to make it effective. Use novalidate with the form declaration to disable the valicate feature of the form. The control section of the form uses an effective set of AngularJS events.
Events in AngularJS
AngularJS provides many events that can be linked to form controls of HTML. For example, ng-click usually attaches to a button. Here are the events supported by AngularJS.
- ng-click
- ng-dbl-click
- ng-mousedown
- ng-mouseup
- ng-mouseenter
- ng-mouseleave
- ng-mousemove
- ng-mouseover
- ng-keydown
- ng-keyup
- ng-keypress
- ng-change
Introducing ng-click directive in AngularJS
Reset the form's data using the ng-click directive of a button.
ten = "ho" type = "text" ng-model = "Ho" required > ten = "ten" type = "text" ng-model = "Ten" required > ten = "email" type = "email" ng-model = "email" required >
Validate data in AngularJS
Here are the variables used to track errors.
- $ dirty - Notice that the data is changed.
- $ invalid - Notice that the input is invalid.
- $ error - Accurate error message.
For example
Here is an example to illustrate the directives introduced above in the AngularJS application:
formtrongAngularjs.html
Vi du Form in AngularJS