Created
September 16, 2014 19:00
-
-
Save enapupe/471dc22f9dff8a4b7ed8 to your computer and use it in GitHub Desktop.
Directive that autofocus an element when scope becomes true
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
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