코드는 매우 간단하기 때문에 말도 안되는 말을 많이하지 않고 코드를 제시합니다.
코드 사본은 다음과 같습니다.
<! doctype html>
<html>
<헤드>
<meta charset = "utf-8">
<title> 제목의 문서 </title>
</head>
<script src = "http : // localhost : 81/js/jquery.js">
</스크립트>
<script src = "http : // localhost : 81/js/angular.min.js">
</스크립트>
<body ng-app = "app">
<div ng-controller = "testctrl">
<div ng- 형태 테스트>
<입력 ng-model = "a"type = "email />
<button ng-click = "do ()">보기 </button>
</div>
</div>
<cript>
app = angular.module ( "app", []);
app.directive ( 'test', function () {<br> // 양식의 명령에는 기본 컨트롤러가 네 번째 매개 변수로 기본 컨트롤러가 있습니다.
var link = function ($ scope, $ element, $ attrs, $ ctrl) {
$ scope.do = function () {
// $ ctrl. $ setDirty ();
Console.log ($ ctrl. $ ristine); // 양식이 수동적이지 않습니까?
Console.log ($ ctrl. $ dirty); // 양식이 수동적입니까?
Console.log ($ ctrl. $ 유효); // 양식이 확인되었는지 여부
Console.log ($ ctrl. $ invalid); // 양식에 오류가 있습니까?
Console.log ($ ctrl. $ 오류); // 양식에 오류 필드가 있습니다
}
}
반품 {
컴파일 : function () {
리턴 링크
},
필요 : '양식',
제한 : 'a'
}
});
app.controller ( 'testctrl', function ($ scope) {
// 컨트롤러가 없으면 아직 초기화되지 않습니다 ..
});
</스크립트>
</body>
</html>
내가 당신과 공유하고 싶은 것은 가장 기본적인 Angularjs 양식 검증입니다. 나는 당신이 그것을 좋아하기를 바랍니다.