One of the functionalities I have implemented is copying data to the clipboard with a button press. However, I am now looking to achieve the same behavior for pasting data from the clipboard. Currently, the paste event only works when interacting with an input field or text area, but I need it to work seamlessly with a button click.
I attempted to utilize window.clipboardData for this purpose, but unfortunately, it did not recognize it. Is there a way to trigger the Paste event through a button press?
Copy(val) {
const selBox = document.createElement('textarea');
selBox.style.position = 'fixed';
selBox.style.left = '0';
selBox.style.top = '0';
selBox.style.opacity = '0';
selBox.value = val;
document.body.appendChild(selBox);
selBox.focus();
selBox.select();
document.execCommand('copy');
document.body.removeChild(selBox);
this.icon = 'checkmark';
this.copyButtonText = 'Copied!';
this.tooltip = true;
}
my html
<button #copyButton [icon]='this.icon' (click)="Copy(this.text)">{{copyButtonText}}</button>
<textarea [disabled]="true"> {{this.text}} </textarea>