Reputation: 11
I have 20 html pages in my project I need to implement a common angular code directive to auto focus on the first input field on all pages.
Upvotes: 0
Views: 944
Reputation: 5736
You can try something like this:
angular.module('utils.autofocus', [])
.directive('autofocus', ['$timeout', function($timeout) {
return {
restrict: 'A',
link : function($scope, $element) {
$timeout(function() {
$element[0].focus();
});
}
}
}]);
// <input type="text" autofocus>
You could also try ng-autofocus
Upvotes: 1