4

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,216
  • 11
  • 30
  • 57
Denis Bellato
  • 156
  • 2
  • 9
  • 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

11

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,022
  • 2
  • 27
  • 30
1

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
  • 60
  • 1
  • 4