AngularJS submission form (form), angularjsform

Source: Internet
Author: User

AngularJS submission form (form), angularjsform

The code is very simple, so we don't need to talk nonsense. We can directly provide the Code:

Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> untitled document </title>
</Head>
<Script src = "http: // localhost: 81/js/jquery. js">
</Script>
<Script src = "http: // localhost: 81/js/angular. min. js">
</Script>
<Body ng-app = "app">
<Div ng-controller = "TestCtrl">
<Div ng-form test>
<Input ng-model = "a" type = "email"/>
<Button ng-click = "do ()"> View </button>
</Div>
</Div>
<Script>
App = angular. module ("app", []);
App. directive ('test', function () {<br> // The form directive has a default controller as the fourth parameter.
Var link = function ($ scope, $ element, $ attrs, $ ctrl ){
$ Scope. do = function (){
// $ Ctrl. $ setDirty ();
Console. log ($ ctrl. $ pristine); // whether the form is passive or not
Console. log ($ ctrl. $ dirty); // whether the form is passive or not
Console. log ($ ctrl. $ valid); // whether the form is verified
Console. log ($ ctrl. $ invalid); // whether error exists in form
Console. log ($ ctrl. $ error); // error field in form
}
}
Return {
Compile: function (){
Return link
},
Require: 'form ',
Restrict: 'A'
}
});
App. controller ('testctrl ', function ($ scope ){
// This object will not be initialized if no contrller exists ..
});
</Script>
</Body>
</Html>

Here we will share with you the most basic angularJS Form Verification and hope you will like it.

Related Article

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.