Skip to content

Instantly share code, notes, and snippets.

@tranphuoctien
Forked from tkh44/focusElement.js
Created March 28, 2016 06:58
Show Gist options
  • Save tranphuoctien/2cb8b892bc768777e484 to your computer and use it in GitHub Desktop.
Save tranphuoctien/2cb8b892bc768777e484 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