Created
July 8, 2013 09:35
-
-
Save EpokK/5947484 to your computer and use it in GitHub Desktop.
focus-me directive
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
<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> |
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('focusMe', function($timeout) { | |
return { | |
scope: { trigger: '@focusMe' }, | |
link: function(scope, element) { | |
scope.$watch('trigger', 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
Thanks! :-)