AngularJS ng-keypressDirective
AngularJS Examples
Code executed when a key is pressed:
<input ng-keypress="count = count + 1" ng-init="count=0" />
<h1>{{count}}</h1>
<h1>{{count}}</h1>
Try it yourself »
Definition and Usage
ng-keypressThe directive is used to tell AngularJS what action to perform when a key is pressed on the specified HTML element.
ng-keypressThe directive does not override the element's native onkeypress event. When the event is triggered,ng-keypressboth the expression and the native onkeypress event will be executed.
Event order for key presses:
- Keydown
- Keypress
- Keyup
Syntax
<element ng-keypress="expression"></element>
<input>, <select>, <textarea>, and other editable elements support this directive.
Parameter Values
| Value | Description |
|---|---|
| expression | The expression to execute when a key is pressed. |
Other Extensions
AngularJS Reference Manual