AngularJS forms and angularjs forms
AngularJS provides rich forms and verification. We can use ng-click to handle AngularJS click button events, and then use the $ dirty and $ invalid flag for verification. Use the novalidate form declaration to prohibit any browser-specific verification. Form Controls use a large number of corner activities. Let's take a quick look at the event first.
Event
AngularJS provides multiple events that can be associated with HTML controls. For example, ng-click is usually associated with a button. The following are 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
Ng-click
Use the command to click a button to reset the data in the form.
<input name="firstname" type="text" ng-model="firstName" required><input name="lastname" type="text" ng-model="lastName" required><input name="email" type="email" ng-model="email" required><button ng-click="reset()">Reset</button><script> function studentController($scope) { $scope.reset = function(){ $scope.firstName = "Mahesh"; $scope.lastName = "Parashar"; $scope.email = "MaheshParashar@yiibai.com"; } $scope.reset();}</script>
Verify data
You can use the following trace error.
- $ Dirty-the specified value has been changed.
- $ Invalid-the status of this value is invalid.
- $ Error-indicates the exact error.
Example
The following example shows all the preceding commands.
TestAngularJS.html
Output
Open textangularjs.html in the webbrowser. The result is as follows.