ng-focus-if

AngularJS directive that will trigger focus on an element under specified conditions
Homepage:
0 people use it
Author: 4262078?v=3 hiebj

ng-focus-if

Bower version NPM version Downloads devDependency Status GitHub stars

An attribute directive that will trigger focus on an element under specified conditions. It can also be used as a cross-browser replacement for the autofocus attribute.

View a live demo on Plnkr.

It is available through NPM:

Or, via bower:

Usage

Include focusIf.min.js in your build or directly with a <script> tag and require the module in your module definition:

To immediately focus an element upon rendering (similar to input autofocus):

To focus an element when a specified Angular expression becomes truthy:

To focus an element after a specified delay upon rendering:

To focus an element after a specified delay when a specified Angular expression becomes truthy:

Caveat: apply focus multiple times

Like any other Angular directive using a $watch callback, this directive depends on Angular's model change detection, which can cause trouble when trying to apply focus more than once. Users looking to apply focus to a given element multiple times may find this thread useful.

comments powered by Disqus
This page was last updated 12 months ago.