Skip to content

Instantly share code, notes, and snippets.

@EpokK
Last active December 18, 2015 22:49
Show Gist options
  • Save EpokK/5857181 to your computer and use it in GitHub Desktop.
Save EpokK/5857181 to your computer and use it in GitHub Desktop.
init focus directive angular js
angular.module('app', []).directive('ngInitFocus', function() {
var timer;
return function(scope, elm, attr) {
if (timer) clearTimeout(timer);
timer = setTimeout(function() {
elm.focus();
}, 0);
};
});
@snadrus
Copy link

snadrus commented Jan 12, 2015

Must be: elm[0].focus()
Even more useful if renamed "autofocus" since it would then be just like page reloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment