Skip to content

Instantly share code, notes, and snippets.

@EpokK
Created July 8, 2013 09:35
Show Gist options
  • Save EpokK/5947484 to your computer and use it in GitHub Desktop.
Save EpokK/5947484 to your computer and use it in GitHub Desktop.
focus-me directive
<button class="btn" ng-click="showForm=true; focusInput=true">show form and focus input</button>
<div ng-show="showForm">
<input type="text" focus-me="focusInput">
<button class="btn" ng-click="showForm=false">hide form</button>
</div>
app.directive('focusMe', function($timeout) {
return {
scope: { trigger: '@focusMe' },
link: function(scope, element) {
scope.$watch('trigger', function(value) {
if(value === "true") {
$timeout(function() {
element[0].focus();
});
}
});
}
};
});
@aruizca
Copy link

aruizca commented Oct 2, 2013

Thanks! :-)

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