ngx-clipboard: call to this._clipboardService.copyFromContent(text) does not work

Hello, I’m using Angular 4 with ngx-clipboard. Static copy to clipboard works but when I want it dynamic with a call to this._clipboardService.copyFromContent(text). It doesn’t work.

I get this error: ERROR in /home/yolo/gestman/src/app/elicitation-form/results/results.component.ts (191,5): Supplied parameters do not match any signature of call target.

Can someone help me? Angular 4 v4.4.7, ngx-clipboard v8.1.4 Thanks a lot Gilles

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 17 (5 by maintainers)

Most upvoted comments

OK this is an issue with executing the copy command itself. It has to be done synchronously from a click command. Programmatically invoking a click invent on the hidden node should make the execCommand() work.

@maxisam thanks for your kind help

  • angular 6.0.6
  • ngx-clipboard 11.1.9
  • zone.js 0.8.26
  • webpack 4.16.3
  • rxjs 6.2.1
import { ClipboardService } from 'ngx-clipboard'

...

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

copy(text: string){
  const copyResult = this._clipboardService.copyFromContent(text);
  console.log(copyResult)
}

// false

I think document.execCommand("copy") is not working in angular.