AngularJS Basic ng keypress Simple Example

  • 2021-07-07 06:05:32
  • OfStack

AngularJS ng-keypress Directive

AngularJS instance

Code to execute when the key is pressed:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="">

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

<h1>{{count}}</h1>

<p> This example calculates the variable every time the input box is released by pressing a key  "count"  Will automatically add  1 . </p>

</body>
</html>

Definition and usage

The ng-keypress instructions are used to tell AngularJS what to do when a key is pressed on a specified HTML element.

The ng-keypress instruction does not override the element's native onkeypress event, and when the event is triggered, both the ng-keypress expression and the native onkeypress event are executed.

Event sequence of keystrokes:

1.Keydown

2.Keypress

3.Keyup

Grammar

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

< input > , < select > , < textarea > And other editable elements support this directive.

Parameter value

描述
expression 按键松开执行的表达式。

The above is the data collation of AngularJS ne-keypress instructions, and the follow-up will continue to be supplemented!


Related articles: