Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copyFromContent not working with longer delay #102

Open
1 task
sanyooh opened this issue Jan 3, 2018 · 7 comments
Open
1 task

copyFromContent not working with longer delay #102

sanyooh opened this issue Jan 3, 2018 · 7 comments

Comments

@sanyooh
Copy link

sanyooh commented Jan 3, 2018

description

I want to copy text to the clipboard which comes from a delayed backend response. Now I tried many different ways to get the text into the clipboard but the command 'execCommand('copy') is not working in the ClipboardService. So I tried the basic functionality and everythings works fine. Then I added delays and when the delay is '2000' it is not able to set text into the clipboard anymore.

Now this hinders my implementation of a feature in our application.

AC

  • the method 'copyFromContent' works when fired after a longer delay

code example

I created a plunker with the basis of the given demo. Please follow this link: https://plnkr.co/edit/PPbwSkngc2QQzCHhNDZg?p=preview

@maxisam
Copy link
Owner

maxisam commented Jan 7, 2018

I can't figure this one out. :(

@indywill
Copy link

I wonder if this is a limitation of the clipboard service, where the "authorization" from the user (the click) has a time limit.
As a work around, one way to solve could be to have 1 button to "prepare" the clipboard content, and a second to perform the actual copy.

@daradermody
Copy link

This fleshes out the problem with execCommand a little more.

I'm also seeing an issue when using the ClipboardService from within a promise where it isn't copying at all regardless of delay. This might be due to some security issues with it being a different thread to the click handler or something (see here).

@ovidiua2003
Copy link

Subscribing to this. After an http request to an API, the clipboard doesn't work anymore. I figured it wont work normally but neither with the clipboard service?

@philip-firstorder
Copy link

Indeed this is a bug, as the main reason to use the copyFromContent function is exactly to handle delays like this

    this.apiService.getURL().subscribe(
      (response: any) => {
        const ret = this.clipboardService.copyFromContent(response);
        console.log(ret); // returns false, nothing is copied
      },

@v-srsi
Copy link

v-srsi commented Jun 5, 2019

I also noticed that

if (container === void 0) { container = this.window.document.body; }
 // check if the temp textarea is still belong the current container.
// In case we have multiple places using ngx-clipboard, one is in a modal using container but the other one is not.
if (this.tempTextArea && !container.contains(this.tempTextArea)) {
    this.destroy(this.tempTextArea.parentElement);
}

throws an error => "container.contains is not a function"

here the container is "body" (string primitive type).

html:

<i class="fa fa-exclamation-circle" style="color:#f1070c;cursor:pointer" aria-hidden="true"
     *ngIf="Status === 'Failed'"
      container="body" placement="right"
      tooltip="Failed to complete. Click icon to copy exception to clipboard"
      ngxClipboard [cbContent]="CompletionMessage"></i>

Am I missing something?

@surajpoddar16
Copy link
Contributor

Container expects a Dom node rather than a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants