Skip to content

Instantly share code, notes, and snippets.

@mcranston18
Last active December 16, 2015 19:19
Show Gist options
  • Save mcranston18/5484656 to your computer and use it in GitHub Desktop.
Save mcranston18/5484656 to your computer and use it in GitHub Desktop.
AngularJS Directive to Validate Field After User Has Left It
App.directive('isFocused', function(){
var isFocused = {
restrict: 'A',
scope: {
model: '=isFocused'
},
link: function(scope, element, attrs) {
scope.model = false;
element.focus(function(){
scope.model = true;
scope.$apply();
});
element.blur(function(){
scope.model = false;
scope.$apply();
});
}
}
return isFocused;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment