how to get clipboard data in angular JS

后端 未结 5 2009
温柔的废话
温柔的废话 2020-12-10 13:14

I was actually looking to get the content of clipboard using angular JS to simulate a copy paste thing.

5条回答
  •  感动是毒
    2020-12-10 13:44

    BTW, if using Angular to copy to clipboard with a Chrome Packaged App, do the following:

    1. Add "clipboardRead" and "clipboardWrite" to the "permissions" in the manifest.json.
    2. use ng-click in your view to feed the value to the controller $scope, like: data-ng-click="copyUrlToClipboard(file.webContentLink)"
    3. Put a function in your controller like:

      $scope.copyUrlToClipboard =  function(url) {
          var copyFrom = document.createElement("textarea");
          copyFrom.textContent = url;
          var body = document.getElementsByTagName('body')[0];
          body.appendChild(copyFrom);
          copyFrom.select();
          document.execCommand('copy');
          body.removeChild(copyFrom);
          this.flashMessage('over5');
      }

提交回复
热议问题