Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

ngclipboard

> 编程语言
Open source

An angularjs directive to copy text to clipboard without using flash

385 stars0 likes1 views
WebsiteGitHub

About

An angularjs directive to copy text to clipboard without using flash

ngclipboard

An angularjs directive to copy text to clipboard without using flash

Angularjs directive for clipboard.js by @zenorocha

Install

You can get it on npm.

bash
npm install ngclipboard --save

Or bower, too.

bower install ngclipboard --save

If you're not into package management, just download a ZIP file.

Setup

First, include angularjs and clipboard.js into your document.

xml

Then Include ngclipboard.js.

xml

Add ngclipboard dependency to your module

javascript
var myApp = angular.module('app', ['ngclipboard']);

Finally, add ngclipboard directive to the wanted html element.

javascript

    Copy to clipboard

Usage

We're living a declarative renaissance, that's why we decided to take advantage of HTML5 data attributes for better usability.

Copy text from another element

A pretty common use case is to copy content from another element. You can do that by adding a data-clipboard-target attribute in your trigger element.

The value you include on this attribute needs to match another's element selector.

xml

    

Cut text from another element

Additionally, you can define a data-clipboard-action attribute to specify if you want to either copy or cut content.

If you omit this attribute, copy will be used by default.

xml

Mussum ipsum cacilds...

    Cut to clipboard

As you may expect, the cut action only works on or elements.

Copy text from attribute

Truth is, you don't even need another element to copy its content from. You can just include a data-clipboard-text attribute in your trigger element.

xml

    Copy to clipboard

Events

There are cases where you'd like to show some user feedback or capture what has been selected after a copy/cut operation.

That's why we fire custom events such as success and error for you to listen and implement your custom logic.

ngclipboard provides you two attributes called ngclipboard-success and ngclipboard-error to listen the clipboard events and implement your custom logic.

xml

    Copy to clipboard
javascript
// You can still access the clipboard.js event
$scope.onSuccess = function(e) {
    console.info('Action:', e.action);
    console.info('Text:', e.text);
    console.info('Trigger:', e.trigger);

    e.clearSelection();
};

$scope.onError = function(e) {
    console.error('Action:', e.action);
    console.error('Trigger:', e.trigger);
}

For a live demonstration, open this site and just your console :)

Browser Support

This library relies on both Selection and execCommand APIs. The first one is supported by all browsers while the second one is supported in the following browsers.

42+ ✔ 12+ ✔ 41+ ✔ 9+ ✔ 29+ ✔ 10+ ✔

The good news is that clipboard.js gracefully degrades if you need to support older browsers. All you have to do is show a tooltip saying Copied! when success event is called and Press Ctrl+C to copy when error event is called because the text is already selected.

License

MIT License

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言