maxisam / ngx-clipboard

A pure angular clipboard directive
http://maxisam.github.io/ngx-clipboard/
MIT License
505 stars 93 forks source link

Page is scrollto Top after use copyFromContent #232

Open luongngochuythanh opened 4 years ago

luongngochuythanh commented 4 years ago

I used copyFromContent function to copy a text. But after paste text, return to page and click to anywhere, the page will scroll to Top. This is what is used

public singleCopy(targetText) {
    if (targetText) {
      this.clipBoardService.copyFromContent(targetText);
    }
  }

Inview:

<div>
     <button class="btn btn-outline-secondary single-copy-btn"
                        (click)="singleCopy(employee['name'])">
      </button>
</div>

Chrome version: 79.0.3945.130 OS: macOS Mojave10.14.4

Does anyone have experience about this or know the way to solve this please help 🙇 ?

maxisam commented 4 years ago

Could you provide an example on stackblitz.com?

I think it is possible to fix that behavior by setting container to body.

<body #container>
    <button ngxClipboard [cbContent]="'target string'" [container]="container">Copy</button>
</body>
Leandro-C-Reis commented 2 years ago

I have a similar issue, the page was scrolling to the top after copying to clipboard and switching to another tab.

It could be solved using configure method. ClipboardService.configure({ cleanUpAfterCopy: true })