Skip to content

Instantly share code, notes, and snippets.

@tkh44
Created March 24, 2014 21:46
Show Gist options
  • Save tkh44/9749895 to your computer and use it in GitHub Desktop.
Save tkh44/9749895 to your computer and use it in GitHub Desktop.
Focus an element. Use the focus-delay="" to delay the focus x amount of ms
ticketApp.directive('focusElement', function($timeout) {
return {
restrict: 'A',
scope: {
focusElement: '@',
focusDelay: '@'
},
link: function($scope, $element, $attrs) {
$scope.$focusElement = angular.isDefined($scope.focusElement) ? $($scope.focusElement): $element;
if (!$scope.$focusElement) return;
$timeout(function() {
$scope.$focusElement.focus();
}, parseInt($scope.focusDelay, 10) || 0);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment