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>
<meta charset="utf-8">
<script src=""></script>
<body ng-app="">

<input ng-keydown="count = count + 1" ng-init="count=0" />


<p> This example calculates the variable every time a key is pressed in the input box  "count"  Will automatically add  1 . </p>


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:





< element ng-keydown="expression" > < /element >

< input > , < select > , < textarea > And other editable elements support this directive.

Parameter value

expression 按下按键执行的表达式。

Related articles: