本人刚开始学习angular,在表单验证这里碰到了一些问题,我的意思是想在blur的时候再让错误提示显示出来,而在focus时不显示错误信息,可是我按照书上的来打,但是不正确,有谁能帮我分析下,谢谢~
js
var app = angular.module('app',[]); app.controller('myCtrl', ['$scope','$timeout', function($scope,$timeout){ }]) app.directive('ngFocus',function(){ // var FOCUS_CLASS = "ng-focused"; return{ restrict : 'A', require : 'ngModel', link : function(scope,ele,attrs,ctrl){ ctrl.$focused = false; ele.bind('focus',function(ev){ // ele.addClass(FOCUS_CLASS); scope.$apply(function(){ ctrl.$focused = true; }); }).bind('blur',function(ev){ // ele.removeClass(FOCUS_CLASS); scope.$apply(function(){ ctrl.$focused = false }) }) } } })