AngularJS Basic ng keydown Simple Example
- 2021-07-07 06:06:06
- OfStack
AngularJS ng-keydown Directive
AngularJS instance
Code to execute when the key is pressed:
<!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-keydown="count = count + 1" ng-init="count=0" />
<h1>{{count}}</h1>
<p> This example calculates the variable every time a key is pressed in the input box "count" Will automatically add 1 . </p>
</body>
</html>
Definition and usage
The ng-keydown instructions are used to tell AngularJS what to do when pressing a key on a specified HTML element.
The ng-keydown instruction does not override the element's native onkeydown event, and when the event is triggered, both the ng-keydown expression and the native onkeydown event are executed.
Event sequence of keystrokes:
1.Keydown
2.Keypress
3.Keyup
Grammar
<
element ng-keydown="expression"
>
<
/element
>
<
input
>
,
<
select
>
,
<
textarea
>
And other editable elements support this directive.
Parameter value
值 | 描述 |
---|---|
expression | 按下按键执行的表达式。 |