5

Is there a chance to implement a paste button in Angular.

FE: User copies a link of the website and on my page when he or she hits a button copied link should appear in a textbox.

Thanks!

INDRAJITH EKANAYAKE
  • 3,894
  • 11
  • 41
  • 63
Denis Bellato
  • 176
  • 2
  • 10
  • 1
    Possible duplicate of [How do I copy to the clipboard in JavaScript?](https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – Edric Mar 31 '19 at 03:33
  • https://stackoverflow.com/questions/50138910/angular-on-paste-event-get-content – Ehsan Kiani Mar 31 '19 at 03:45

2 Answers2

12

You can only copy from a webpage programmatically. You cannot programmatically paste anything because this is a security violation. However, you can add

(paste)="onPaste($event)" 

to get the pasted clipboard details from control + v

Dilshan Liyanage
  • 4,440
  • 2
  • 31
  • 33
3

Now is possible to read Clipboard from the new Clipboard Api like this:

navigator.clipboard.readText().then(
      text => {
        yourVariable = text;
      }
     )
      .catch(error => {
        console.error('Cannot read clipboard text: ', error);
      }
    );

A popup will appear asking to the user if they want to allow this operation.

Marc Guillem
  • 134
  • 1
  • 7