Created
February 9, 2017 04:32
-
-
Save israelcrux/f66e4710abb2b9d88f952b03680a6f5d to your computer and use it in GitHub Desktop.
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
(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