Created
October 10, 2014 21:37
-
-
Save Skinner927/b465c3f3cc8a44635e94 to your computer and use it in GitHub Desktop.
AngularJs Directive - Give Focus To
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
.directive('giveFocusTo', ['$timeout', function($timeout){ | |
return { | |
restrict: 'A', | |
link: function(scope, el, attrs){ | |
el.on('click', function(e){ | |
if(e.preventDefault === 'function'){ | |
e.preventDefault(); | |
} | |
var id = '#'+attrs.giveFocusTo; | |
var ele = angular.element(id); | |
// Focus on the next digest | |
$timeout(function(){ | |
ele.trigger('focus'); | |
}); | |
}); | |
} | |
}; | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment