Created
June 30, 2013 15:01
-
-
Save designingsean/5895474 to your computer and use it in GitHub Desktop.
AngularJS GetFocus directive. If the expression is truthy, then the element receives the focus.
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
app.directive('ngGetFocus', function() { | |
return { | |
restrict: 'A', | |
link: function(scope, element, attr){ | |
scope.$watch(attr.ngGetFocus, function(value){ | |
if(value) | |
element.focus(); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://jsfiddle.net/designingsean/Qz3zm/ for how this works.