AngularJS ng-focusDirective
AngularJS Example
Execute an expression when the input field gets focus:
<input ng-focus="count = count + 1" ng-init="count=0" />
<h1>{{count}}</h1>
<h1>{{count}}</h1>
Try it Yourself »
Definition and Usage
ng-focusThe directive is used to tell AngularJS what to do when an HTML element gets focus.
ng-focusThe directive does not override the element's original onfocus event. When the event is triggered,ng-focusboth the expression and the original onfocus event will execute.
Syntax
<element ng-focus="expression"></element>
This directive is supported by <a>, <input>, <select>, <textarea>, and window objects.
Parameter Value
| Value | Description |
|---|---|
| expression | The expression to execute when the element gets focus. |
Other Extensions
AngularJS Reference Manual