-
-
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
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
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