Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

AngularJS ng-keypress Directive

AngularJS ng-keypress Instruction

AngularJS Reference Manual AngularJS Reference Manual


AngularJS Examples

Code to execute when a key is pressed:

<

input

ng-keypress=

"count = count + 1"

ng-init=

"count=0"

/

<

h1

{{count}}

<

/h1

Try it »


Definition and Usage

ng-keypress The directive tells AngularJS the action to take when a key is pressed on the specified HTML element.

ng-keypress The directive does not override the element's native onkeypress event. When the event is triggered,ng-keypress both the expression and the native onkeypress event will be executed.

The event order of key strokes:

  1. Keydown
  2. Keypress
  3. Keyup

Syntax

<

element

ng-keypress=

"expression"

<

/element

,


Parameter value

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

AngularJS Reference Manual AngularJS Reference Manual