how to get clipboard data in angular JS

后端 未结 5 1987
温柔的废话
温柔的废话 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:47

    I had the same issue and I used angular-clipboard feature[1] which uses new Selection API and Clipboard API available in the latest browsers.

    First we have to install angular-clipboard lib, i'm using bower.

    $ bower install angular-clipboard --save
    

    To import the module use following in html.

    
    

    To set values to element using $scope in controller

    $scope.textToCopy = 'Testing clip board';
    

    Load the clipboard module using,

    angular.module('testmodule', ['angular-clipboard']);
    

    This works for Chrome 43+, Firefox 41+, Opera 29+ and IE10+.

    Its simple & worked fine.

    [1] https://www.npmjs.com/package/angular-clipboard

    Thanks,

提交回复
热议问题