AngularJS ng-keypressDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Examples

Code executed when a key is pressed:

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

<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:

  1. Keydown
  2. Keypress
  3. 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.

AngularJS 参考手册AngularJS Reference Manual

Other Extensions