angularjs ng-keypress directive

angularjs example

Code executed when the key is pressed:

<! Doctype html>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<body ng-app="">
<input ng-keyup="count=count + 1" ng-init="count=0" />
<p>In this example, every time the key in the input box is released,The calculated variable "count" is automatically incremented by one.</p>

Definition and usage

The ng-keypress directive is used to tell angularjs what action is required when pressing a key on the specified html element.

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

Sequence of keystrokes:





<element ng-keypress="expression"></element>

<input> ;,<select> ;,<textarea> ;, and other editable elements support the directive.

Parameter value

value description
expression Press the key to release the executed expression.

  • Previous Detailed Bitmap of Android picture cache (1)
  • Next IOS animation to achieve rain and cherry blossom special effects