AngularJS ng-focus directive
AngularJS instance
Execute the expression when the input box gets focus:
<!DOCTYPE html><html><head><meta charset="utf-8"><script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script></head><body ng-app=""><input ng-focus="count = count + 1" ng-init="count=0" /><h1>{{count}}</h1><p>This instance automatically adds 1 to the calculation variable "count" every time the input box gets focus. </p></body></html>The calculation variable "count" will automatically add 1 each time this instance gets the focus in the input box.
Definition and usage
The ng-focus directive is used to tell AngularJS what to do when an HTML element gets focus.
The ng-focus directive will not overwrite the element's original onfocus event. When the event is triggered, both the ng-focus expression and the original onfocus event will be executed.
grammar
<element ng-focus="expression"></element>
The directive is supported by the <a>, <input>, <select>, <textarea>, and window objects.
Parameter value
| value | describe |
|---|---|
| Expression | The expression executed when the element gets focus. |
The above is the basic information of Angular ng-focus, and will be supplemented later.