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.