AngularJS ng-keydownDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Example

Code to execute when a key is pressed:

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

<h1>{{count}}</h1>

Try it Yourself »

Definition and Usage

ng-keydownThe directive is used to tell AngularJS what to do when a key is pressed on the specified HTML element.

ng-keydownThe directive does not override the element's native onkeydown event. When the event is triggered,ng-keydownboth the expression and the native onkeydown event will be executed.

Event order for key presses:

  1. Keydown
  2. Keypress
  3. Keyup

Syntax

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

The directive is supported by <input>, <select>, <textarea>, and other editable elements.


Parameter Value

Value Description
expression The expression to execute when a key is pressed.

AngularJS 参考手册AngularJS Reference Manual

Other Extensions