Code Monkey home page Code Monkey logo

ngx-clipboard's Introduction

Financial Contributors on Open Collective ngx-clipboard 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

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 - 12.x, please use version 14.0.2.
  • If you need to use it on 13.x, please use version 15.x.x. (Also thanks https://github.com/arturovt for updating & tuning)

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]

ngx-clipboard's People

Contributors

adgoncal avatar akialapiha avatar alejanp avatar arturovt avatar billypon avatar chimurai avatar coenmooij avatar datumgeek avatar dependabot[bot] avatar euangoddard avatar filipsl27 avatar fknop avatar guillaume-ro-fr avatar jsmike avatar junglebarry avatar krico avatar mathieucoupe avatar mattlewis92 avatar maxisam avatar monkeywithacupcake avatar npmcdn-to-unpkg-bot avatar phra avatar safeeval avatar sam-lin-millerslab avatar saulshanabrook avatar siddhantsood avatar surajpoddar16 avatar tabuckner avatar theoomoregbee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-clipboard's Issues

This won't compile strict for me

I'm getting three errors.

  1. clipboard.service.ts(1,18): error TS6133: 'InjectionToken' is declared but never used.
    which is pretty much exactly what it says, and is resolved by removing the declaration
  2. clipboard.directive.ts(26,55): error TS6133: 'onClick' is declared but never used.
    which is resolved by making the method Public instead of Private
  3. clipboard.directive.ts(26,63): error TS6133: 'button' is declared but never used.
    which is resolved by making it _button

Thanks.

Unexpected value 'ClipboardModule' imported by the module 'AppModule'

Just this morning, i got error 'Unexpected value 'ClipboardModule' imported by the module 'AppModule'' in my app. It worked fine last week. I use ver 1.4.0.
I can't use the latest since currently i'm using angular ver 2.0.0.
What's the stable version for angular 2.0.0?
Could you please be advised about this?
Thanks

Angular2 - Issue wih clipboard after i18n integration

On running npm run i18n command, getting the below error:
Error: ENOENT: no such file or directory, open 'dist\out-tsc\node_modules\ngx-clipboard\src\window.service.metadata.json'
at Error (native)
at Object.fs.openSync (fs.js:641:18)
at Object.fs.writeFileSync (fs.js:1347:33)
at MetadataWriterHost.writeMetadata (\node_modules@angular\tsc-wrapped\src\compiler_host.js:164:22)
at MetadataWriterHost.writeFile (\node_modules@angular\tsc-wrapped\src\compiler_host.js:143:19)
at Object.writeFile \node_modules\typescript\lib\typescript.js:45369:132)
at Object.writeFile (\node_modules\typescript\lib\typescript.js:7602:14)
at writeEmittedFiles (\node_modules\typescript\lib\typescript.js:37859:20)
at doEmit (\node_modules\typescript\lib\typescript.js:37719:17)
at emitFile (\node_modules\typescript\lib\typescript.js:44665:21)
Extraction failed

Additional Information:
"angular/compiler-cli": "^2.3.1",
"types/jasmine": "2.5.38",
"types/node": "^6.0.42",
"types/lodash": "4.14.50",
"angular-cli": "1.0.0-beta.26",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"typescript": "~2.0.3",
"ngx-clipboard": "6.0.6"

"scripts": {
"i18n": "ng-xi18n -p src/tsconfig.json"
}

[cbContent] not working

the [cbContent] does not work in angular 4, i have tried the other option but i need to defien an inputTarget but since i am displaying a list of urls dynamically i cant create inputtargets dynamically

the [cbContent] grabs the value, but doesnt put it in the clipboard

Clipboard is not defined

In 'angular2-clipboard/src/clipboard.directive.ts' file, Your code import Clipboard = require('clipboard'); make a mistake, chrome does not support this kind of writing

@angular/core has no exported member 'InjectionToken' in v7.0.3

When trying to build my application, I get the following error:

ERROR in /build/node_modules/ngx-clipboard/src/clipboard.service.ts (2,18): Module '"/build/node_modules/@angular/core/index"' has no exported member 'InjectionToken'.

I am using Angular v2.4.10 and ngx-clipboard v7.0.3. From my understanding, InjectionToken is only available in Angular v4, so maybe it needs to be removed from this line?

webpack warning: Cannot find SourceMap

I use webpack to bundle my project and it always shows this warning:

WARNING in ./~/ngx-clipboard/dist/index.js
Cannot find SourceMap '/home/travis/build/maxisam/ngx-clipboard/index.js.map': Error: Can't resolve './/home/travis/build/maxisam/ngx-clipboard/index.js.map' in 'C:\...\node_modules\ngx-clipboard\dist'
 @ ./~/ngx-clipboard/index.js 1:0-23
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts

I checked the index.js file and found this line at the end:
//# sourceMappingURL=/home/travis/build/maxisam/ngx-clipboard/index.js.map

The index.js.map file is in the same directory as the index.js but the path is wrong. Can you fix this?

I get the same warning in this file:
WARNING in ./~/ngx-clipboard/dist/clipboard.directive.js

But the path is correct in the index.umd.js file.

6.0.5 errors due to BrowserModule

With 6.0.5 I get an error on my lazily loaded modules using the ClipboardModule:

Uncaught (in promise): Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.

I do not load ClipboardModule in my main bundle but only in lazily loaded modules using

imports: [
  ClipboardModule.forRoot()
]

The problem is that it imports BrowserModule, it should import CommonModule instead.

Error postinstall

npm install angular2-clipboard --save

[email protected] postinstall /assets/node_modules/angular2-clipboard
npm run typings

[email protected] typings /assets/node_modules/angular2-clipboard
typings install --ambient

typings ERR! deprecated The "ambient" flag is deprecated. Please use "global" instead

$ typings --version
1.0.4

Send to clipboard by code (TypeScript)

Hi,
the current demos show me how I can bind angular2-clipboard to a button click event to copy text of control to clipboard.
I would like to send text to clipboard, for example, on changed-event of an input. For example, when user changes the text, I would like to send the calculated result directly to clipboard without requiring any action from user. Is it possible? Can you give me a hint how to do that?

traceur not found

Hello,
After importing ClipboardModule into my app.module.ts I am getting:
editor:25 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/traceur(…).

This is how my systemjs.config.js looks like:

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core':                    'npm:@angular/core/bundles/core.umd.js',
      '@angular/common':                  'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler':                'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser':        'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic':'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http':                    'npm:@angular/http/bundles/http.umd.js',
      '@angular/router':                  'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms':                   'npm:@angular/forms/bundles/forms.umd.js',

      // other libraries
      'rxjs':                       'npm:rxjs',
      'angular-in-memory-web-api':  'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'moment':                     'npm:/moment/moment.js',
      'angular2-uuid':              'npm:angular2-uuid/index.js',
      'ng2-bootstrap':              'npm:ng2-bootstrap/bundles/ng2-bootstrap.umd.js',
      'angular2-tree-component':    'npm:angular2-tree-component',
      'lodash':                     'npm:lodash',
      'ngx-clipboard':              'npm:ngx-clipboard'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      'app'                       : { main: './main.js', defaultExtension: 'js' },
      'rxjs'                      : { defaultExtension: 'js' },
      'node_modules/ng2-bootstrap': { defaultExtension: "js" },
      'angular2-tree-component'   : { main: 'dist/angular2-tree-component.js', defaultExtension: 'js' },
      'lodash'                    : { main: 'lodash.js', defaultExtension: 'js' },
      'ngx-clipboard'             : { main: 'index.js', defaultExtension: 'js' }
    }
  });
})(this);

and package.json:

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "lite": "lite-server"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@angular/common": "^2.3.1",
    "@angular/compiler": "^2.3.1",
    "@angular/core": "^2.3.1",
    "@angular/forms": "~2.0.1",
    "@angular/http": "~2.0.1",
    "@angular/platform-browser": "^2.3.1",
    "@angular/platform-browser-dynamic": "^2.3.1",
    "@angular/router": "~3.0.1",
    "@angular/upgrade": "~2.0.1",
    "angular-in-memory-web-api": "~0.1.1",
    "angular2-tree-component": "1.3.3",
    "angular2-uuid": "^1.1.0",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "lodash": "^4.17.2",
    "ng2-bootstrap": "^1.1.16",
    "ngx-clipboard": "^3.0.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.26"
  },
  "devDependencies": {
    "@types/chai": "^3.4.34",
    "concurrently": "^3.0.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.3",
    "typings": "^1.4.0"
  },
  "repository": {}
}

Do you have any idea if this is caused by something on my or the clipboard's side? Thanks in advance!

Not working with Rollup

I am attempting to upgrade my application to the latest version of ng2 (2.4.1) & in the process reduce the need for 3rd party code maintained outside of npm (because of AoT and rollup issues).
I'm using the latest version of your plugin, and getting the following error when I run the rollup step:
image

Can't compile when "noImplicitAny" is true

There's a few compile errors when including the package within an Angular CLI project. You get the follow errors when building following an NPM install:

ERROR in /node_modules/ngx-clipboard/src/clipboard.service.ts (10,9): Parameter 'document' implicitly has an 'any' type.
/node_modules/ngx-clipboard/src/clipboard.service.ts (11,9): Parameter 'window' implicitly has an 'any' type.
/node_modules/ngx-clipboard/src/clipboard.service.ts (102,52): Parameter 'doc' implicitly has an 'any' type.
/node_modules/ngx-clipboard/src/clipboard.service.ts (102,57): Parameter 'win' implicitly has an 'any' type.

ERROR in /node_modules/ngx-clipboard/src/clipboard.directive.ts (27,63): Parameter 'button' implicitly has an 'any' type.
/node_modules/ngx-clipboard/src/clipboard.directive.ts (42,26): Parameter 'succeeded' implicitly has an 'any' type.
/node_modules/ngx-clipboard/src/clipboard.directive.ts (42,37): Parameter 'copiedContent' implicitly has an 'any' type.

The changes are nothing too drastic, just explicitly defining the types of the mentioned variables. I'll create a pull request shortly with the changes if you could get them merge into the NPM version that would be great.

TypeError: Clipboard is not a constructor

Hi,
I'm a beginner with Angular and I'm trying to integrate your library. Everything works well in development mode but when I try to browserify my app (or using systemjs-builder) I get this error :

TypeError: Clipboard is not a constructor
with the corresponding line :
this.clipboard = new Clipboard(this.elmRef.nativeElement, option);

after investigating a little bit, I noticed that in order to work, the code should be :
this.clipboard = new Clipboard.default(this.elmRef.nativeElement, option);

but I have no idea how to fix that...
edit: changing the tscconfig.json module from "es2015" to "commonJS" and compiling the project seems to work. The biggest change is that the resulted files use require('clipboard'); instead of import
Could the import/export mechanism be broken somewhere ?

No provider for ClipboardService!

I thought I found the fix when I saw issue #45. But when I try .forRoot(), typescript complains that `Property .forRoot() does not exist on type 'typeof ClipboardModule'. When I look inside my node_modules/ngx-clipboard/src/index.ts, I see that indeed that's true. Am I missing anything? I have v8.0.2 installed.

The end goal is to use the isSupported method inside the service so I can show/hide the copy action. Is there another way to do this since it's not documented?

Error in ngii-clipboard.directive.ts

Hi there,
by installing the Module and trying to run it with my angular2 application.
I've got the following Error Log:

ERROR in ./~/angular2-clipboard/src/ngii-clipboard.directive.ts
(2,28): error TS2307: Cannot find module 'clipboard'.

Is there any Explanation for that ?

Thanks

Can't compile version 7.0.4 with angular 2.x

Hi,
when I try to compile with ng build --prod a project created with angular-cli 1.0.0, I've got the following error:

ERROR in Error encountered resolving symbol values statically. Could not resolve type Document (position 11:45 in the original .ts file), resolving symbol ClipboardService in /Users/-/node_modules/ngx-clipboard/src/clipboard.service.ts

I am using version 7.0.4 of ngx-clipboard and this is my tsconfig.json:
{ "compileOnSave": false, "compilerOptions": { "target": "es6", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "es2016" ] } }

RC5 gives errors

Awesome module, though in RC5 is not working.
Giving a following errors:

metadata_resolver.js:704Uncaught TypeError: Cannot read property 'type' of null(anonymous function) @ metadata_resolver.js:704getTransitiveModules @ metadata_resolver.js:703CompileMetadataResolver.getTransitiveNgModuleMetadata @ metadata_resolver.js:417CompileMetadataResolver.getNgModuleMetadata @ metadata_resolver.js:289RuntimeCompiler.compileComponents @ runtime_compiler.js:157RuntimeCompiler.compileModuleAndComponents @ runtime_compiler.js:79RuntimeCompiler.compileModuleAsync @ runtime_compiler.js:56PlatformRef.bootstrapModuleWithZone @ application_ref.js:374PlatformRef.bootstrapModule @ application_ref.js:367(anonymous function) @ main.ts:9__webpack_require @ bootstrap f173efc…:52(anonymous function) @ ngii-clipboard.directive.ts:20__webpack_require__ @ bootstrap f173efc…:52webpackJsonpCallback @ bootstrap f173efc…:23(anonymous function) @ main.bundle.js:1
client:54 [WDS] Errors while compiling.
client:56 [default] /Projects/WebApp/node_modules/angular2-clipboard/src/ngii-clipboard.directive.ts:2:0
Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.errors @ client:56sock.onmessage @ client:90EventTarget.dispatchEvent @ eventtarget.js:58(anonymous function) @ main.js:299SockJS._transportMessage @ main.js:297EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:60wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:56 [default] /Projects/WebApp/node_modules/angular2-clipboard/src/ngii-clipboard.directive.ts:2:27
Cannot find module 'clipboard'.errors @ client:56sock.onmessage @ client:90EventTarget.dispatchEvent @ eventtarget.js:58(anonymous function) @ main.js:299SockJS._transportMessage @ main.js:297EventEmitter.emit @ emitter.js:50WebSocketTransport.ws.onmessage @ websocket.js:60wrapFn @ zone.js:769ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423
client:56 [default] /Projects/WebApp/node_modules/angular2-clipboard/src/ngii-clipboard.directive.ts:21:20
Cannot find name 'ClipboardOptions'.

Canno't compile when targeting es6

Hi, this package is not working when targeting es6.

Here is the error:

Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

No provider for ClipboardService!

I'm using Webpack and run the install and then add the ClipboardModule to my module file. When I add the button to my template, I see the above error.

import { ClipboardModule } from 'ngx-clipboard';

imports: [ // import Angular's modules BrowserModule, FormsModule, HttpModule, ClipboardModule, RouterModule.forRoot(ROUTES, { useHash: true, preloadingStrategy: PreloadAllModules }) ],

Template:
<button class="btn btn-default" type="button" [ngxClipboard]="field_field.id">copy</button>

Sorry if this is the wrong venue, just not sure what else I'm missing for this to be erring like this.

Source files are missing

I previously got warnings because the paths to the source map files were wrong (#33).
I updated to version 5.0.3 and the paths are correct.
But now the source files are missing and so I get this warning:

WARNING in ./~/ngx-clipboard/dist/index.js
Cannot find source file '../index.ts': Error: Can't resolve '../index.ts' in 'C:\[...]\node_modules\ngx-clipboard\dist'
 @ ./src/app/app.module.ts 14:0-48
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/main.ts

Please add the source files to the node module. Because the map files do not make sense without the source files.
Thanks!

Error in clipboard.directive.ts

[default] .../node_modules/ngx-clipboard/dist/clipboard.directive.d.ts:1:1 
    Cannot find type definition file for 'clipboard'.
[default] .../node_modules/ngx-clipboard/dist/clipboard.directive.d.ts:3:28 
    Cannot find module 'clipboard'.
[default] Checking finished with 2 errors

Any idea ?

tslint error in ClipboardDirective

Error:
./node_modules/ngx-clipboard/src/clipboard.directive.ts[12, 5]: In the class "ClipboardDirective", the directive input property "targetElm" should not be renamed.Please, consider the following use "@input() targetElm: string"

tsconfig.json:
"exclude": [
"bin",
"node_modules",
"node_modules/ngx-clipboard/src/**"
]

tslint run:
tslint rules: npm run lint

more instructions in README, please?

I'm using the module and directive now and it's working great, but I've been fumbling around and if you could, I think it'd be great to give more step-by-step instructions on using it.

The plunker is great, but it's using the angular2-clipboard and clipboard off of npmcdn and it's not clear (at least to someone who hasn't installed third-party directives before) what the "right" system-config.ts changes are, so for now I'm actually using the same npmcdn approach like the plunker is.

I'd love if the README could include a more specific list like:

  1. npm install angular2-clipboard --save
  2. make these changes to the map and packages in system-config.ts (or however you have SystemJS configured)
  3. in the component where you want to use it, import {ClipboardDirective} from 'angular2-clipboard';
  4. add ClipboardDirective to the directives array for the component that will use it
  5. use in the template per plunker example

NOTE: if I knew the correct instructions, I'd happily do this as a pull request myself, but can't figure out the right systemjs config to get it working from my node_modules version instead of npmcdn

Thanks!!

Latest version incompatible with Angular CLI

I've installed latest version like this:

npm install ngx-clipboard --save

I'm using Angular CLI and there is a problem with v5.0.3 of this module.

I have to use 4.0.0 in my package.json.

Please update de documentation and the module in order to use Webpack and AngularCLI. SystemJS is in decline

could be run delayed ?

hi, i use ngx-clipboard with java api result. i try to copy returned result from api service but it does not copy for the first attempt because of service delay. ngx-clipboard runs normally intantly copy, but i try to delayed copy. is there a way to succeed it firt attempt too.

Modularize it to be able to compile with AoT

It would be if it can be as a module in order to be able to compile it with AoT compilation mode. Actually it's a module but I am getting, Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

I read your comment about changing to commonjs but I need to use es2015 in order to be able to compile using AoT

Unexpected value

Got the following error when calling the ClipboardModule in app.module.ts

Uncaught Error: Unexpected value 'ClipboardModule' imported by the module 'AppModule'

Any help please ?
Thanks

Expanded example?

I've been looking through this repos demo folder but can't see how to use this aside from needing to add it to the app.module folder. I'm using angular2/typescript and webpack, is there a more full example somewhere online that shows how to import/reference it in my component and component template?

Could not find a declaration file for module 'ngx-clipboard'

Hi,

Just upgraded to Angular 4 and trying to do AOT compilation I get the following while compiling using:

node_modules/.bin/ngc -p src/tsconfig-aot.json

Error at /Users//src/app/app.module.ts:31:33: Could not find a declaration file for module 'ngx-clipboard'. '//node_modules/ngx-clipboard/dist/index.js' implicitly has an 'any' type.

This is using the latest version of ngx clipboard.

Any help is appreciated.

Cheers, Tom

Not working with Aot and Rollup

Error - While building my app with aot and rollup gets this error.

image

Here is my package.json

 {
 "name": "demo",
 "version": "1.0.0",
 "description": "",
 "main": "index.js",
 "scripts": {
"aot": "node_modules/.bin/ngc -p wwwroot/tsconfig-aot.json",
"rollup": "node_modules/.bin/rollup -c wwwroot/rollup-config.js",
"cleanup": "rimraf wwwroot/app/aot && rimraf wwwroot/build.js"
 },
"author": "",
"license": "ISC",
"dependencies": {
"angular/animations": "4.1.3",
"angular/common": "4.1.3",
"angular/compiler": "4.1.3",
"angular/compiler-cli": "4.1.3",
"angular/core": "4.1.3",
"angular/forms": "4.1.3",
"angular/http": "4.1.3",
"angular/material": "2.0.0-beta.6",
"angular/platform-browser": "4.1.3",
"angular/platform-browser-dynamic": "4.1.3",
"angular/platform-server": "4.1.3",
"angular/router": "4.1.3",
"angular/upgrade": "4.1.3",
"core-js": "2.4.1",
"ngx-clipboard": "8.0.3",
"rxjs": "5.4.0",
"systemjs": "0.20.13",
 "zone.js": "0.8.11"
 },
"devDependencies": {
"ngx-window-token": "0.0.2"
 "rollup": "0.43.0",
 "rollup-plugin-commonjs": "8.0.2",
 "rollup-plugin-node-resolve": "3.0.0",
 "rollup-plugin-uglify": "2.0.1",
 "typescript": "2.2.2",
 "rimraf": "2.6.1"
 }
 }

Here is my tsconfig-aot.json

  {
 "compilerOptions": {
 "target": "es5",
 "module": "es2015",
 "moduleResolution": "node",
 "sourceMap": true,
 "emitDecoratorMetadata": true,
 "experimentalDecorators": true,
 "lib": [ "es2016", "dom" ],
 "noImplicitAny": false,
 "suppressImplicitAnyIndexErrors": true
 },
"files": [
"app/app.module.ts",
"app/main-aot.ts"
],

"angularCompilerOptions": {
"genDir": "app/aot",
"skipMetadataEmit": true
}
}

Here is my rollup.config.js

import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify';

export default {
entry: 'wwwroot/app/main-aot.js',
dest: 'wwwroot/build.js', // output a single application bundle
sourceMap: false,
format: 'iife',
onwarn: function (warning) {
    // Skip certain warnings

    // should intercept ... but doesn't in some rollup versions
    if (warning.code === 'THIS_IS_UNDEFINED') { return; }

    // console.warn everything else
    console.warn(warning.message);
 },
 plugins: [
    nodeResolve({ jsnext: true, module: true }),
    commonjs({
        include: 'node_modules/**',
    }),
    uglify()
]
}

Thanks in advance

Does not work with 'disabled' input/textareas

Hi. Thanks for your work on this plugin!

I wanted to use this on a disabled textarea, but the copy didn't work. There were no errors in the console. It simply did not copy the text in the text area. Removing the 'disabled' attribute from the textarea made the copy work.

I know that there are other ways of doing this (like with [cbContent]) but it would make it more flexible if it could handle 'disabled' input and textareas.

console log error on app load

The app works, but I get the following error in build/load:

client?93b6:76 [default] c:\xampp\htdocs\ImyApp\node_modules\angular2-clipboard\src\clipboard.directive.ts:2:0 
Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

AOT Compilation fails for Angular CLI 1.0.0

I get these errors when I use ng build --prod with CLI version 1.0.0 and version 5.0.9 of ngx-clipboard.

ERROR in C:/git/fspg-web-full-stack/guestrec-frontend/src/$$_gendir/node_modules/ngx-clipboard/src/clipboard.directive.ngfactory.ts (36,20): Property 'targetElm' is private and only accessible within class 'ClipboardDirective'.
C:/git/fspg-web-full-stack/guestrec-frontend/src/$$_gendir/node_modules/ngx-clipboard/src/clipboard.directive.ngfactory.ts (43,20): Property 'cbContent' is private and only accessible within class 'ClipboardDirective'.
C:/git/fspg-web-full-stack/guestrec-frontend/src/$$_gendir/node_modules/ngx-clipboard/src/clipboard.directive.ngfactory.ts (61,53): Property 'cbOnSuccess' is private and only accessible within class 'ClipboardDirective'.
C:/git/fspg-web-full-stack/guestrec-frontend/src/$$_gendir/node_modules/ngx-clipboard/src/clipboard.directive.ngfactory.ts (62,53): Property 'cbOnError' is private and only accessible within class 'ClipboardDirective'.

ERROR in C:/git/fspg-web-full-stack/guestrec-frontend/src/$$_gendir/node_modules/ngx-clipboard/src/clipboard.directive.ngfactory.ts (36,20): Property 'targetElm' is private and only accessible within class 'ClipboardDirective'.
C:/git/fspg-web-full-stack/guestrec-frontend/src/$$_gendir/node_modules/ngx-clipboard/src/clipboard.directive.ngfactory.ts (43,20): Property 'cbContent' is private and only accessible within class 'ClipboardDirective'.
C:/git/fspg-web-full-stack/guestrec-frontend/src/$$_gendir/node_modules/ngx-clipboard/src/clipboard.directive.ngfactory.ts (61,53): Property 'cbOnSuccess' is private and only accessible within class 'ClipboardDirective'.
C:/git/fspg-web-full-stack/guestrec-frontend/src/$$_gendir/node_modules/ngx-clipboard/src/clipboard.directive.ngfactory.ts (62,53): Property 'cbOnError' is private and only accessible within class 'ClipboardDirective'.

It looks like it's because you have private @input variables on the directive class. With AOT compilation these cannot be private.

Getting Error when running application with ngx-clipboard

I have installed the ngx-clipboard package and

  1. added entry in the appmodule.ts

Add sample code in the component as given in the demo

I get the below error when running the application :


export * from './dist';
Uncaught SyntaxError: Unexpected token export(…)

Suggestion upon improving the Event emit

Hi,

currently the directive only emits a true as event whether its 'success' or 'error'. I would suggest that instead of a boolean, you could emit the event itself so that in the (cbOnSucces) you can refer to the text for example:

@output() public cbOnSuccess: EventEmitter< Event > = new EventEmitter< Event >();

@output() public cbOnError: EventEmitter< Event > = new EventEmitter< Event >();

..

this.clipboard.on('success', (e) => this.cbOnSuccess.emit(e));
this.clipboard.on('error', (e) => this.cbOnError.emit(e));

Module Clipboard Not Found

image

My System.config.json

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function(global) {
    // map tells the System loader where to look for things
    var map = {
        'app':                        'app', // 'dist',
        '@angular':                   'node_modules/@angular',
        'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
        'rxjs':                       'node_modules/rxjs'
    };
    // packages tells the System loader how to load when no filename and/or no extension
    var packages = {
        'app':                        { main: './public/js/main.js',  defaultExtension: 'js' },
        'rxjs':                       { defaultExtension: 'js' },
        'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }
    };
    var ngPackageNames = [
        'common',
        'compiler',
        'core',
        'http',
        'platform-browser',
        'platform-browser-dynamic',
        'router',
        'router-deprecated',
        'upgrade',
    ];
    // Individual files (~300 requests):
    function packIndex(pkgName) {
        packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
    }
    // Bundled (~40 requests):
    function packUmd(pkgName) {
        packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
    }
    // Most environments should use UMD; some (Karma) need the individual index files
    var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
    // Add package entries for angular packages
    ngPackageNames.forEach(setPackageConfig);
    var config = {
        map: map,
        packages: packages
    };
    System.config(config);
})(this);

Errors with PhantomJS (evaluating 'global.ng.core')

Hi,

I am trying to run npm test with using PhantomJS but i got a few errors and have no idea how to fix this.
Im using Angular-seed project https://github.com/mgechev/angular-seed
I installed ngx-clipboard 8.0.2
added to systemjs and karma.conf.js

START:                                                                                                                        
09 05 2017 15:25:01.909:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/                                   
09 05 2017 15:25:01.911:INFO [launcher]: Launching browsers PhantomJS, PhantomJS_custom with unlimited concurrency            
09 05 2017 15:25:01.917:INFO [launcher]: Starting browser PhantomJS                                                           
09 05 2017 15:25:01.957:INFO [launcher]: Starting browser PhantomJS                                                           
09 05 2017 15:25:01.994:INFO [phantomjs.launcher]: ACTION REQUIRED:                                                           
09 05 2017 15:25:01.995:INFO [phantomjs.launcher]:                                                                            
09 05 2017 15:25:01.995:INFO [phantomjs.launcher]:   Launch browser at                                                        
09 05 2017 15:25:01.995:INFO [phantomjs.launcher]:   http://localhost:9000/webkit/inspector/inspector.html?page=2             
09 05 2017 15:25:01.995:INFO [phantomjs.launcher]:                                                                            
09 05 2017 15:25:01.995:INFO [phantomjs.launcher]: Waiting 15 seconds ...                                                     
09 05 2017 15:25:03.526:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#tIhQCb7DSZw5aI6CAAAA with id 1129970  
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR                                                                                       
  TypeError: undefined is not an object (evaluating 'global.ng.core')                                                         
  at node_modules/ngx-clipboard/dist/bundles/ngxClipboard.umd.min.js:1                                                        
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR                                                                                       
  TypeError: undefined is not an object (evaluating 'global.ng.core')                                                         
  at node_modules/ngx-clipboard/dist/bundles/ngxClipboard.umd.min.js:1                                                        
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR                                                                                       
  TypeError: undefined is not an object (evaluating 'global.ng.core')                                                         
  at node_modules/ngx-window-token/dist/bundles/ngxWindowToken.umd.min.js:1                                                   
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR                                                                                       
  TypeError: undefined is not an object (evaluating 'global.ng.core')                                                         
  at node_modules/ngx-window-token/dist/bundles/ngxWindowToken.umd.min.js:1                                                   
09 05 2017 15:25:18.559:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#Qyry5kyE0TBos395AAAB with id 58374266 
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR                                                                                       
  TypeError: undefined is not an object (evaluating 'global.ng.core')                                                         
  at node_modules/ngx-clipboard/dist/bundles/ngxClipboard.umd.min.js:1                                                        
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR                                                                                       
  TypeError: undefined is not an object (evaluating 'global.ng.core')                                                         
  at node_modules/ngx-clipboard/dist/bundles/ngxClipboard.umd.min.js:1                                                        
                                                                                                                              
Finished in 0.904 secs / 0 secs @ 15:25:19 GMT+0200 (Romance Daylight Time)                                                   
                                                                                                                              
SUMMARY:                                                                                                                      
√ 0 tests completed                                                                                                           
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR                                                                                       
  TypeError: undefined is not an object (evaluating 'global.ng.core')                                                         
  at node_modules/ngx-window-token/dist/bundles/ngxWindowToken.umd.min.js:1                                                   
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR                                                                                       
  TypeError: undefined is not an object (evaluating 'global.ng.core')                                                         
  at node_modules/ngx-window-token/dist/bundles/ngxWindowToken.umd.min.js:1                                                   
                                                                                                                              
× Error while running the tests! Exit code: 1                                                                                 
                                                                                                                              
npm ERR! Test failed.  See above for more details.     
`

I hope someone can help me with this, thanks

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.