รหัสนั้นง่ายมากดังนั้นฉันจึงไม่พูดเรื่องไร้สาระมากแค่นำเสนอรหัส:
การคัดลอกรหัสมีดังนี้:
<! doctype html>
<html>
<head>
<meta charset = "utf-8">
<tite> เอกสารชื่อ UNT </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>
<อินพุต ng-model = "a" type = "อีเมล" />
<button ng-click = "do ()"> ดู </button>
</div>
</div>
<script>
app = angular.module ("app", []);
app.directive ('ทดสอบ', function () {<br> // คำสั่งของแบบฟอร์มฟอร์มมีคอนโทรลเลอร์เริ่มต้นเป็นพารามิเตอร์ที่สี่
var link = function ($ scope, $ element, $ attrs, $ ctrl) {
$ scope.do = function () {
// $ ctrl. $ setDirty ();
console.log ($ ctrl. $ pristine); // แบบฟอร์มไม่ใช่แบบพาสซีฟ?
console.log ($ ctrl. $ สกปรก); // เป็นแบบฟอร์มหรือไม่?
console.log ($ ctrl. $ ถูกต้อง); // ไม่ว่าจะมีการตรวจสอบแบบฟอร์ม
console.log ($ ctrl. $ ไม่ถูกต้อง); // มีข้อผิดพลาดใด ๆ ในรูปแบบ
console.log ($ ctrl. $ ข้อผิดพลาด); // มีฟิลด์ข้อผิดพลาดในรูปแบบ
-
-
กลับ {
คอมไพล์: ฟังก์ชัน () {
ลิงก์กลับ
-
ต้องการ: 'ฟอร์ม',
จำกัด : 'A'
-
-
app.controller ('testctrl', ฟังก์ชั่น ($ scope) {
// หากไม่มีคอนโทรลเลอร์สิ่งนี้จะไม่เริ่มต้น ..
-
</script>
</body>
</html>
สิ่งที่ฉันต้องการแบ่งปันกับคุณคือการตรวจสอบแบบ AngularJS ขั้นพื้นฐานที่สุดฉันหวังว่าคุณจะชอบ