AngularJS Form details and sample code, angularjs sample code

Source: Internet
Author: User

AngularJS Form details and sample code, angularjs sample code

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.

The above is the knowledge of AngularJS forms, and we will continue to add relevant knowledge in the future. Thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.