Skip to content

Instantly share code, notes, and snippets.

@travisjeffery
Created May 3, 2012 18:49
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save travisjeffery/2588075 to your computer and use it in GitHub Desktop.
Save travisjeffery/2588075 to your computer and use it in GitHub Desktop.
Angularjs Focus Directive
<script>
angular.directive('tj:focus', function(){
return function(scope, element){
element[0].focus();
};
});
</script>
<div>
<input type="text" ng:model="model" tj:focus />
</div>
@petrbela
Copy link

Seems that in the new version the arguments are shifted, so the header for the inner function should be function(scope, element)

@travisjeffery
Copy link
Author

Cool, updated!

@pbojinov
Copy link

short, sweet and gets the job done

@Werninator
Copy link

Wow, thank you for this simple solution! Gonna try it out.

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