AngularJS Basic ng copy Instruction Instance Code

  • 2021-07-06 10:12:02
  • OfStack

AngularJS ng-copy Directive

AngularJS instance

Executes the expression when the text of the input box is copied:


<!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-copy="count = count + 1" ng-init="count=0" value=" Copy this text " />

<p> The text is copied  {{count}}  Times. </p>

<p> Variables in an instance  "count"  The value of is automatically increased when the text of the input box is copied  1 . </p>

</body>
</html>

Note: The value of the variable "count" in the instance is automatically incremented by 1 when the text in the input box is copied.

Definition and usage

The ng-copy instructions are used to tell AngularJS what to do when the HTML element text is copied.

The ng-copy instruction does not override the element's original oncopy event, and when the event is fired, both the ng-copy expression and the original oncopy event are executed.

Grammar

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

All HTML elements are supported.

Parameter value

描述
expression 元素文本被拷贝时执行的表达式。

The above is the basic data of ng-copy instruction, and the friends who learn AngularJS refer to it.


Related articles: