ng-autofocus
A simple attribute directive that will trigger focus on an element under specified conditions.
It is available through NPM:
npm install ng-autofocus
Or, via bower:
bower install hiebj/ng-autofocus --save
Usage
Include autofocus.min.js
in your build or directly with a <script>
tag and require the module in your module definition:
angular
.module('App', [
'autofocus',
... // other dependencies
]);
To immediately focus an element upon rendering:
<input autofocus />
To focus an element when a specified conditional $scope
property becomes truthy:
<input autofocus="focusInput" />
To focus an element after a specified delay upon rendering:
<input autofocus autofocus-delay="500" />
To focus an element after a specified delay when a specified conditional $scope
property becomes truthy:
<input autofocus="focusInput" autofocus-delay="500" />