Skip to content

Instantly share code, notes, and snippets.

@israelcrux
Created February 9, 2017 04:32
Show Gist options
  • Save israelcrux/f66e4710abb2b9d88f952b03680a6f5d to your computer and use it in GitHub Desktop.
Save israelcrux/f66e4710abb2b9d88f952b03680a6f5d to your computer and use it in GitHub Desktop.
(function(){
angular.module('app.directives')
.directive('focusWhen', focusWhen);
function focusWhen(){
var directive = {};
directive.link = link;
directive.scope = {
focus_event : '=focusWhen'
};
return directive;
function link(scope, element, attrs){
if(scope.focus_event){
scope.$on(scope.focus_event, function() {
setTimeout(function() {
element[0].focus();
element[0].select();
}, 10);
});
}
}
}
})();
// use it as <div focus-when="the-name-of-your-event" >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment