<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.
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