Created
March 4, 2014 10:05
-
-
Save lovelykaushik86/9343612 to your computer and use it in GitHub Desktop.
AngularJS ngFocusOut directive - If you are new in angularJs you can use this by adding in your HTML tag. e.g. <input type = "text" ng-focus-out = "$scope.bool = true">
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
appStrapDirectives.directive('ngFocusOut', function( $timeout ) { | |
return function( $scope, elem, attrs ) { | |
$scope.$watch(attrs.ngFocusOut, function( newval ) { | |
if ( newval ) { | |
$timeout(function() { | |
elem[0].focusout(); | |
}, 0, false); | |
} | |
}); | |
}; | |
}); |
Except when you need to do something before the element loses focus and not after the fact. Very useful if you are trying to save out selection from text area/input before losing focus for drag and drop.
you could use the built-in ng-blur instead:
ng-focus="focused=true" ng-blur="focused=false"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I too needed something like this... wrote my own directive, worked like a charm. Then I discovered that this is essentially the ng-blur directive. https://docs.angularjs.org/api/ng/directive/ngBlur