Created
January 29, 2014 18:19
-
-
Save francoishill/8693785 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # CoffeeScript directive to focus an element when a property changes | |
| # Thanks to: http://stackoverflow.com/questions/14833326/how-to-set-focus-in-angularjs | |
| masterApp.directive "takeFocus", ["$timeout", "$parse", ($timeout, $parse) -> | |
| link: (scope, element, attrs) -> | |
| model = $parse(attrs.takeFocus) | |
| scope.$watch model, (value) -> | |
| if value is true | |
| $timeout -> | |
| element[0].focus() | |
| return | |
| return | |
| element.bind "blur", -> | |
| scope.$apply model.assign(scope, false) | |
| return | |
| return | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment