Skip to content

Instantly share code, notes, and snippets.

@enapupe
Created September 16, 2014 19:00
Show Gist options
  • Save enapupe/471dc22f9dff8a4b7ed8 to your computer and use it in GitHub Desktop.
Save enapupe/471dc22f9dff8a4b7ed8 to your computer and use it in GitHub Desktop.
Directive that autofocus an element when scope becomes true
myApp.directive("focusMe", function($timeout){
return {
restrict: "A",
link: function(scope, element, attrs){
scope.$watch(attrs.focusMe, function(value){
if(value === true){
$timeout(function(){
element[0].focus();
});
}
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment