Blur directive for AngularJS

Unfortunately, there is no native support for blur event in AngularJS. With this directive you can handle blur event in your AngularJS controllers:
1:  Module.directive('blur', function() {  
2:    return {  
3:     restrict: 'A',  
4:     link: function postLink(scope, element, attrs) {  
5:       element.bind('blur', function () {  
6:       scope.$apply(attrs.ngBlur);  
7:     });  
8:    }  
9:    };  
10:  });  
Now you can use it:
1:  <input type="text" blur="handleBlur()"></input>  
And handler for it:
1:  yourController = function($scope){  
2:    $scope.handleInputBlur = function(){  
3:      // do some action here  
4:    }  
5:  }  

Comments