Skip to content

Instantly share code, notes, and snippets.

@Skinner927
Created October 10, 2014 21:37
Show Gist options
  • Save Skinner927/b465c3f3cc8a44635e94 to your computer and use it in GitHub Desktop.
Save Skinner927/b465c3f3cc8a44635e94 to your computer and use it in GitHub Desktop.
AngularJs Directive - Give Focus To
.directive('giveFocusTo', ['$timeout', function($timeout){
return {
restrict: 'A',
link: function(scope, el, attrs){
el.on('click', function(e){
if(e.preventDefault === 'function'){
e.preventDefault();
}
var id = '#'+attrs.giveFocusTo;
var ele = angular.element(id);
// Focus on the next digest
$timeout(function(){
ele.trigger('focus');
});
});
}
};
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment