Last active
December 18, 2015 22:49
-
-
Save EpokK/5857181 to your computer and use it in GitHub Desktop.
init focus directive angular js
This file contains hidden or 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
angular.module('app', []).directive('ngInitFocus', function() { | |
var timer; | |
return function(scope, elm, attr) { | |
if (timer) clearTimeout(timer); | |
timer = setTimeout(function() { | |
elm.focus(); | |
}, 0); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Must be: elm[0].focus()
Even more useful if renamed "autofocus" since it would then be just like page reloads.