1

I'm using ngx-clipboard to copy some text to clipboard in my Angular application.

  constructor(
    private clipboardService: ClipboardService,
  ) {
    this.subscribeToClipboard();
  }

  subscribeToClipboard() {
    this.clipboardService.copyResponse$.subscribe((res: IClipboardResponse) => {
      console.log('res', res);
      if (res.isSuccess) {

      } else {

      }
    });
  }

  triggerOnClick(content) {
    this.clipboardService.copyFromContent(content);
  }

The contents are actually copied to the clipboard when triggerOnClick is called. But the subscription to copyResponse$ does not work and I do not get any value in it when copy is done.

Angular: 8.1.0

ngx-clipboard: 12.3.0

What could be going wrong here?

user5155835
  • 4,392
  • 4
  • 53
  • 97

1 Answers1

0

I have had the same problem as described. Versions are the same Angular 8 and ngx-clipboard 12.3.0.

I completely followed the installation and usage guide. I decided to go with the ClipboardService. I did not received any responses in this.clipboardService.copyResponse$ Observable. I did some investigation and discovered that directive and its events are working as expected, but not the service.

It seems that the problem is in the copyFromContent method. It does not push any responses into the copyResponse$ Observable.

Try to use this.clipboardService.copy method instead. Worked for me.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77