Home > Web Front-end > JS Tutorial > body text

angularJS submit form (form)_AngularJS

WBOY
Release: 2016-05-16 16:15:04
Original
971 people have browsed it

The code is very simple, so I won’t go into too much nonsense and just give you the code:

Copy code The code is as follows:





Untitled Document





                                                                                                            
& Lt; button ng-click = "do ()" & gt; view & lt;/button & gt;
                                                                                       

<script><br> ​ app = angular.module("app",[]);<br> App.directive('test',function() {<br>      //Form form instructions have a default controller as the fourth parameter<br>         var link = function($scope, $element, $attrs, $ctrl) {<br> $scope.do = function() {<br> //$ctrl.$setDirty();<br>                     console.log($ctrl.$pristine); //Has the form not been touched?<br>                      console.log($ctrl.$dirty); //Whether the form has been passive<br>                     console.log($ctrl.$valid); //Whether the form has been verified <br>                       console.log($ctrl.$invalid); //Is there any error in the form<br>                          console.log($ctrl.$error); //Fields with errors in the form<br>             }<br> }<br>          return {<br>                compile: function() {<br>                     return link<br>             },<br>               require: 'form',<br>              restrict: 'A'<br> }<br> });<br> ​ app.controller('TestCtrl', function($scope){<br> ​​​​ //If there is no controller, this thing will not be initialized..<br>         });<br> </script>




What I share with you here is the most basic angularJS form verification. I hope you will like it.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!