An AngularJS simple directive that uses ZeroClipboard and updates the user's clipboard.
Download the from here
bower install zeroclipboard ng-clip
npm install zeroclipboard ng-clip
ng-clip is available at cdnjs
Add ng-clip.js and ZeroClipboard.js to your main file (index.html)
Update the .swf path location using ngClipProvider
.config(['ngClipProvider', function(ngClipProvider) {
ngClipProvider.setPath("bower_components/zeroclipboard/dist/ZeroClipboard.swf");
}]);
Set ngClipboard
as a dependency in your module
var myapp = angular.module('myapp', ['ngClipboard'])
Add clip-copy directive to the wanted element, example:
<a href="https://github.com/asafdav/ng-clip/blob/master/" clip-copy="getTextToCopy()" clip-click="doSomething()">Copy</a>
You can optionally override zeroclipboard config parameters using ngClipProvider
ngClipProvider.setConfig({
zIndex: 50
});
You can optionally specify the MIME type by providing using the clip-copy-mime-type
attribute:
<a href="https://github.com/asafdav/ng-clip/blob/master/" clip-click="getHtmlToCopy()" clip-copy-mime-type="text/html">Copy HTML</a>
You can also optionally provide a fallback function that gets called if flash is unavailable:
<a href="https://github.com/asafdav/ng-clip/blob/master/" clip-click-fallback="fallback(copy)" clip-copy="getTextToCopy()" clip-click="doSomething()">Copy</a>
If the fallback function is defined to accept an argument named copy
, that argument will be populated with the text to copy.
set auto-hide-on-no-flash = true
, it is used to hide button copy when browser flash is none, default auto-hide-on-no-flash = false
, example:
<a href="https://github.com/asafdav/ng-clip/blob/master/" auto-hide-on-no-flash="true" clip-copy="getTextToCopy()" clip-click="doSomething()">Copy</a>
You can check out this live example here: http://plnkr.co/xwV5Yn see the examples folder for more