AngularJS Basic ng focus Simple Example
- 2021-07-07 06:10:29
- OfStack
AngularJS ng-focus Directive
AngularJS instance
Executes 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 evaluates the variable every time the input box gets focus "count" Will automatically add 1 . </p>
</body>
</html>
This instance automatically increments the calculation variable "count" by 1 each time the input box gets focus.
Definition and usage
The ng-focus instructions are used to tell AngularJS what to do when an HTML element gets focus.
The ng-focus instruction does not override the element's original onfocus event, and when the event is fired, both the ng-focus expression and the original onfocus event are executed.
Grammar
<
element ng-focus="expression"
>
<
/element
>
<
a
>
,
<
input
>
,
<
select
>
,
<
textarea
>
, and window objects support this directive.
Parameter value
值 | 描述 |
---|---|
expression | 元素获取焦点时执行的表达式。 |
The above is the basic data collation of Angular ng-focus, which will be supplemented in the future.