1.0.35 • Published 8 years ago

ng2-clipboard v1.0.35

Weekly downloads
86
License
ISC
Repository
github
Last release
8 years ago

ng2-clipboard

a simple component and service for copying text to the user's clipboard.

installation:

npm i --save ts-clipboard
npm i --save ng2-clipboard

usage:

importing in angular-seed (mgechev) project

project.config.ts:

  let additionalPackages: ExtendPackages[] = [{
    name: 'ng2-clipboard',
    path: 'node_modules/ng2-clipboard/index.js'
  },
  {
    name: 'ng2-font-awesome',
    path: 'node_modules/ng2-font-awesome/index.js'
  },
  {
    name: 'ts-clipboard',
    path: 'node_modules/ts-clipboard/ts-clipboard.js'
  }];

  this.addPackagesBundles(additionalPackages);

bundling with systemjs builder

importing the module

import { ClipboardModule } from 'ng2-clipboard';
...


#### ClipboardComponent

all of the below usages are valid:

```html
<clipboard-component [content]="someText" [faIcon]="true"></clipboard-component>
<br/>
<clipboard-component [content]="someText" [img]="'assets/img/terribleIcon.png'" [altText]="'copy to clipboard'"></clipboard-component>
<br/>
<clipboard-component [content]="someText" [text]="'click to copy'" [altText]="'copy to clipboard'"></clipboard-component>
<br/>
<clipboard-component [content]="someText" [img]="'assets/img/terribleIcon.png'" [faIcon]="true" [text]="'click to copy'"></clipboard-component>
<br/>
}

output

alt text

ClipboardService

import { Component, OnInit } from '@angular/core';
import { ClipboardService } from 'ng2-clipboard/ng2-clipboard';

@Component({
  moduleId: module.id,
  selector: 'sd-home',
  template: `
<div class="card card-dp">
  <button class="btn btn-primary" (click)="copyToClipboard()">copy to clipboard</button>
  <pre>{{someText}}</pre>
</div>
  `,
  styleUrls: ['home.component.css'],
})

export class HomeComponent implements OnInit {

  constructor(private clipboard: ClipboardService) { }
  errorMessage: string;
  someText: string = `
this
is some
nicely
formatted text`;

  copyToClipboard = () => { this.clipboard.copy(this.someText); }

  ngOnInit() { }

}

output

alt text

imports:

  @Input() content: string; // the text to be copied
  @Input() altText: string = 'copy to clipboard'; // the title / altText to be displayed on mouseover
1.0.35

8 years ago

1.0.34

8 years ago

1.0.33

8 years ago

1.0.32

8 years ago

1.0.31

8 years ago

1.0.30

8 years ago

1.0.29

8 years ago

1.0.28

8 years ago

1.0.27

8 years ago

1.0.26

8 years ago

1.0.25

8 years ago

1.0.24

9 years ago

1.0.23

9 years ago

1.0.21

9 years ago

1.0.20

9 years ago

1.0.19

9 years ago

1.0.18

9 years ago

1.0.17

9 years ago

1.0.16

9 years ago

1.0.15

9 years ago

1.0.14

9 years ago

1.0.13

9 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago