AngularJS module to focus an HTML input element.
Run the bower's install command or download this repository.
bower install angular-focus-it
Include the angular-focus-it.min.js file.
<script src="bower_components/angular-focus-it/angular-focus-it.min.js"></script>Add the focusIt module in your app dependencies.
angular.module('app', [
'focusIt'
])To use in your controller, add focus in your controller dependencies.
.controller('HomeCtrl', ['$scope', 'focus', function($scope, focus) {
focus('name');
var timeout = 500; // milliseconds, 1000 ms = 1 second
focus('type', timeout); // param timeout is optional e has default value = 0
}]);Using in the directives:
- The
focus-idattribute to set the id of the target element to focus. - The
focus-onattribute to set the event name to trigger the focus.
<button type="button" focus-id="age" focus-on="click">Focus age</button>
<button type="button" focus-id="search" focus-on="click" focus-timeout="400">Focus Search</button>Angular FocusIt is freely distributable under the terms of the MIT license.