AngularJS – ng-copy 指令


在 AngularJS 中,ng-copy 指令用於在複製輸入文字欄位中的文字時指定任何自定義行為。我們可以使用此指令來呼叫某些方法,這些方法將在從輸入欄位複製文字時觸發。所有型別的輸入元素都支援此指令。

語法

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

示例 - ngCopy 指令

在 Angular 專案目錄中建立一個 "ngCopy.html" 檔案,然後複製貼上以下程式碼片段。

<!DOCTYPE html>
<html>
   <head>
      <title>ngCopy Directive</title>

      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

      <style>
         .index {color: white; background-color: green;}
      </style>
   </head>

   <body ng-app style="text-align: center;">
      <h1 style="color: green;">
         Welcome to Tutorials Point
      </h1>
      <h2>
         AngularJS | ngCopy Directive
      </h2>

      <div ng-init="isCopy=false; copy='Copy this text!'">
         <textarea ng-copy="isCopy=true" ng-model="copy"> </textarea>
         <br />

         <pre>Copied status: {{isCopy}}</pre>
      </div>
   </body>
</html>

輸出

要執行以上程式碼,只需轉到你的檔案並像普通 HTML 檔案一樣執行它。你將看到瀏覽器視窗上的以下輸出。

更新於: 08-10-2021

243 瀏覽量

開啟你的 職業生涯

完成本課程並獲得認證

開始
廣告
© . All rights reserved.