Ví dụ:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<form ng-app="" name="myForm">
Email:
<input type="email" name="myAddress" ng-model="text">
Lỗi email: {{myForm.myAddress.$error.email}}
</form>
</body>
</html>
Giải thích: Nếu lỗi định dạng email trả về là True , còn đúng định dạng trả về False (không lỗi)
Tiếp bước 2: ta hiển thị câu thông báo Email chưa đúng khi nhập sai định dạng email
Ví du:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<form ng-app="" name="myForm">
Email:
<input type="email" name="myAddress" ng-model="text">
<span ng-show="myForm.myAddress.$error.email">Email chưa đúng </span>
</form>
</body>
</html>
Giải thích: ng-show là True thì đối tượng hiện thị, False thì ẩn , nếu như email không đúng trả về True là hiển thị câu thông báo ra.
Kiểm tra email đã nhập đúng chưa angular