AngularJS ng-keypress directive
Definition and Usage
ng-keypress
The instruction tells AngularJS what operations to perform when using the keyboard on a specific HTML element.
In AngularJS ng-keypress
The directive does not override the original onkeypress event of the element, both will be executed.
The order of keystrokes is:
- Keydown (Keyboard Pressed)
- Keypress (Keyboard Press)
- Keyup (Keyboard Release)
Example
Execute an expression each time a key is pressed:
<input ng-keypress="count = count + 1" ng-init="count=0" /> <h1>{{count}}</h1>
Syntax
<element ng-keypress="expression</element>
Support <input>
,<select>
,<textarea>
and other editable elements.
Parameters
Parameters | Description |
---|---|
expression | An expression that is executed when a key is pressed. |