AngularJS ng-keydownDirective
AngularJS Example
Code to execute when a key is pressed:
<input ng-keydown="count = count + 1" ng-init="count=0" />
<h1>{{count}}</h1>
<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:
- Keydown
- Keypress
- 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. |
Other Extensions
AngularJS Reference Manual