Coder Social home page Coder Social logo

mattlewis92 / ngx-clipboard Goto Github PK

View Code? Open in Web Editor NEW

This project forked from maxisam/ngx-clipboard

0.0 3.0 0.0 1.13 MB

A pure angular clipboard directive

Home Page: http://maxisam.github.io/ngx-clipboard/

License: MIT License

JavaScript 8.58% TypeScript 78.14% CSS 4.24% HTML 9.03%

ngx-clipboard's Introduction

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

  • Angular >=6.0.0

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.

The code are pretty much the same, in 8.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 copyFromContent from ClipboardService to copy any text you dynamically created.
import { ClipboardService } from 'ngx-clipboard'

...

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

copy(text: string){
  this._clipboardService.copyFromContent(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}

Example

stackblitz.com

Build project

1. npm i

2. 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.

ngx-clipboard's People

Contributors

maxisam avatar guillaume-ro-fr avatar phra avatar safeeval avatar alejanp avatar adgoncal avatar datumgeek avatar jsmike avatar saulshanabrook avatar theoomoregbee avatar akialapiha avatar billypon avatar npmcdn-to-unpkg-bot avatar siddhantsood avatar filipsl27 avatar

Watchers

James Cloos avatar Matt Lewis avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.