Der Code ist sehr einfach, daher spreche ich nicht viel Unsinn. Präsentiere einfach den Code:
Die Codekopie lautet wie folgt:
<! docType html>
<html>
<kopf>
<meta charset = "utf-8">
<title> bis zum Titel "Dokument" </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>
<Eingabe ng-model = "a" type = "mail" />
<button ng-klick = "do ()"> anzeigen </button>
</div>
</div>
<Script>
app = angular.module ("App", []);
app.directive ('test', function () {<br> // Die Befehle des Formularformulars haben einen Standardcontroller als viertes Parameter
var link = function ($ scope, $ element, $ attrs, $ ctrl) {
$ scope.do = function () {
// $ ctrl. $ setDirty ();
console.log ($ ctrl. $ Pristine); // ist Form nicht passiv?
console.log ($ ctrl. $ Dirty); // ist Form passiv?
console.log ($ ctrl. $ gültig); // ob das Formular überprüft wurde
console.log ($ ctrl. $ ungültig); // Gibt es einen Fehler in Form
console.log ($ ctrl. $ error); // Es gibt ein Fehlerfeld in Form
}
}
zurückkehren {
kompilieren: function () {
Return Link
},
erfordern: 'Form',,
einschränken: 'a' '
}
});
app.controller ('testctrl', function ($ scope) {
// Wenn es keinen Controller gibt, wird dieses Ding noch nicht initialisiert.
});
</script>
</body>
</html>
Was ich mit Ihnen teilen möchte, ist die grundlegendste AngularJS -Formüberprüfung. Ich hoffe, es gefällt Ihnen.