All Projects → maxisam → Ngx Clipboard

maxisam / Ngx Clipboard

Licence: mit
A pure angular clipboard directive

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ngx Clipboard

Use Clipboard Copy
📋 Lightweight copy to clipboard hook for React
Stars: ✭ 256 (-41.82%)
Mutual labels:  clipboard
Clipjump
📋 Clipboard Manager for Windows, built in AutoHotkey
Stars: ✭ 305 (-30.68%)
Mutual labels:  clipboard
Clip
Cross-platform C++ library to copy/paste clipboard content
Stars: ✭ 341 (-22.5%)
Mutual labels:  clipboard
Pasteboard Viewer
📋 Inspect the system pasteboards on macOS
Stars: ✭ 257 (-41.59%)
Mutual labels:  clipboard
Wsl Ssh Agent
Helper to interface with Windows ssh-agent.exe service from Windows Subsystem for Linux (WSL)
Stars: ✭ 298 (-32.27%)
Mutual labels:  clipboard
Extrakto
tmux - quickly select, copy/insert/complete text without a mouse
Stars: ✭ 320 (-27.27%)
Mutual labels:  clipboard
angular4-seed-starter
An angular4 starter with webpack2+aot+lazyload+hmr+scss(个人搭的angular4 starter,使用webpack2,包含aot、lazyload、scss、热替换功能等等)
Stars: ✭ 23 (-94.77%)
Mutual labels:  aot
Scala Native
Your favorite language gets closer to bare metal.
Stars: ✭ 4,053 (+821.14%)
Mutual labels:  aot
Awesome Graal
A curated list of awesome resources for Graal, GraalVM, Truffle and related topics
Stars: ✭ 302 (-31.36%)
Mutual labels:  aot
Copyq
Clipboard manager with advanced features
Stars: ✭ 4,346 (+887.73%)
Mutual labels:  clipboard
React Clipboard.js
React wrapper for clipboard.js (flashless clipboard)
Stars: ✭ 266 (-39.55%)
Mutual labels:  clipboard
Angularx Qrcode
Angular4/5/6/7/8/9/10/11 QRCode generator component library for QR Codes (Quick Response) with AOT support based on node-qrcode
Stars: ✭ 281 (-36.14%)
Mutual labels:  aot
Angular2 Aot Webpack
Angular AOT (Ahead Of Time) offline compilation example with Webpack
Stars: ✭ 325 (-26.14%)
Mutual labels:  aot
Shapeshifter
A clipboard manager for the 21st century.
Stars: ✭ 256 (-41.82%)
Mutual labels:  clipboard
Ngx Cookie Service
Angular (4.2+ ...11) service for cookies. Originally based on the `ng2-cookies` library.
Stars: ✭ 363 (-17.5%)
Mutual labels:  aot
angular-webpack-skeleton
This project is deprecated. Please refer to https://github.com/Ks89/angular-cli-skeleton
Stars: ✭ 16 (-96.36%)
Mutual labels:  aot
Clipboard
Ruby access to the clipboard on Windows, Linux, macOS, Java, Cygwin, and WSL 📋︎
Stars: ✭ 310 (-29.55%)
Mutual labels:  clipboard
Gotem
Copy to clipboard for modern browsers in less than 1kb.
Stars: ✭ 439 (-0.23%)
Mutual labels:  clipboard
Aspect Injector
AOP framework for .NET (c#, vb, etc)
Stars: ✭ 398 (-9.55%)
Mutual labels:  aot
Ngx Meta
Dynamic page title & meta tags utility for Angular (w/server-side rendering)
Stars: ✭ 331 (-24.77%)
Mutual labels:  aot

Financial Contributors on Open Collective travis build npm GitHub release npm

ngx-clipboard , F.K.A angular2-clipboard

From 6.0.0, there is no other JS dependency anymore. Just Angular.

It works with angular version 2.0.0 and up

To make more sense with the future versioning scheme of Angular, the directive selector is now rename to ngxClipboard

Other packages

Dependencies

  • If you need to use it on 2.x, please use version 7.x.x.
  • If you need to use it on 4.x, please use version 8.x.x.
  • If you need to use it on 5.x, please use version 10.x.x.
  • If you need to use it on 8.x, please use version 12.x.x.
  • If you need to use it on 9.x, please use version 13.x.x.
  • If you need to use it on 10.x, please use version 14.x.x.

The code are pretty much the same, in v8.0.0 it uses InjectionToken which requires angular4 and above.

Install

You can get it on npm.

npm install ngx-clipboard --save

Open your module file e.g app.module.ts and update imports array

import { ClipboardModule } from 'ngx-clipboard';
...
imports: [
...
    ClipboardModule,
...
]

Usage

If you use SystemJS to load your files, you might have to update your config:

System.config({
    map: {
        'ngx-clipboard': 'node_modules/ngx-clipboard'
    }
});

Copy source

This library support multiple kinds of copy source.

  • Setting cbContent attribute
<button ngxClipboard [cbContent]="'target string'">Copy</button>

You can assign the parent container to avoid focus trapper issue, #145

<div #container>
    <button ngxClipboard [cbContent]="'target string'" [container]="container">Copy</button>
</div>
  • Setting an input target
....

<input type="text" #inputTarget />

<button [ngxClipboard]="inputTarget">Copy</button>
  • Using copy from ClipboardService to copy any text you dynamically created.
import { ClipboardService } from 'ngx-clipboard'

...

constructor(private _clipboardService: ClipboardService){
...
}

copy(text: string){
  this._clipboardService.copy(text)
}

Callbacks

  • cbOnSuccess callback attribute is triggered after copy was successful with $event: {isSuccess: true, content: string}
<button (cbOnSuccess)="copied($event)" [cbContent]="'example string'">Copied</button>

Or updating parameters directly like so

<button (cbOnSuccess)="isCopied = true" [cbContent]="'example string'">Copied</button>
  • cbOnError callback attribute is triggered when there's failure in copying with $event:{isSuccess: false}

Conditionally render host

You can also use the structural directive *ngxClipboardIfSupported to conditionally render the host element

<button ngxClipboard *ngxClipboardIfSupported [cbContent]="'target string'" (cbOnSuccess)="isCopied = true">
    Copy
</button>

Special thanks to @surajpoddar16 for implementing this feature

Handle copy response globally

To handle copy response globally, you can subscribe to copyResponse$ exposed by the ClipboardService

export class ClipboardResponseService {
  constructor(
    private _clipboardService: ClipboardService,
    private _toasterService: ToasterService
  ) {
    this.handleClipboardResponse();
  }

  handleClipboardResponse() {
    this._clipboardService.copyResponse$.subscribe((res: IClipboardResponse) => {
      if (res.isSuccess) {
        this._toasterService.pop('success', undefined, res.successMessage);
      }
    });
  }
}

Special thanks to @surajpoddar16 for implementing this feature

Clean up temporary textarea used by this module after each copy to clipboard

This library creates a textarea element at the root of the body for its internal use. By default it only destroys it when the directive is destroyed. If you'd like it to be destroyed after each copy to clipboard, provide root level module configuration like this:

ClipboardService.configure({ cleanUpAfterCopy: true });

Special thanks to @DmitryEfimenko for implementing this feature

Example

stackblitz.com

Build project

npm i && npm run build

To run demo code locally

npm run start

Contributing

  • Your commits conform to the conventions established here

Troubleshooting

Please ask your general questions at https://stackoverflow.com/questions/tagged/ngx-clipboard

Shoutouts 🙏

Kudos to

Thierry Templier This project is inspired by his answer on StackOverflow.

The core function is ported from clipboard.js by @zenorocha.

This project was generated with Angular CLI version 7.

BrowserStack Logo

Big thanks to BrowserStack for letting the maintainers use their service to debug browser issues.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].