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.
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
Ung Dung AngularJSng-app = "ungdungAngularjs" ng-controller = "sinhvienController" >
Result:
Open the formtrongAngularjs.html page in the browser and see the results.
Form in AngularJS Picture 1
Follow tutorialspoint
Previous lesson: Modules in AngularJS
Next article: Include syntax in AngularJS
You should read it
- Directive in AngularJS
- HTML DOM element in AngularJS
- What is AngularJS?
- View components in AngularJS
- Instructions for installing AngularJS
- Ajax in AngularJS
- The Filter in AngularJS
- The Service in AngularJS
- Expression in AngularJS
- The Module in AngularJS
- Create the table in AngularJS
- Create the first AngularJS application