I am trying to implement an icon that when clicked will save a variable to the user\'s clipboard. I have currently tried several libraries and none of them have been able to
First suggested solution works, we just need to change
selBox.value = val;
To
selBox.innerText = val;
i.e.,
HTML:
.ts file:
copyMessage(val: string){
const selBox = document.createElement('textarea');
selBox.style.position = 'fixed';
selBox.style.left = '0';
selBox.style.top = '0';
selBox.style.opacity = '0';
selBox.innerText = val;
document.body.appendChild(selBox);
selBox.focus();
selBox.select();
document.execCommand('copy');
document.body.removeChild(selBox);
}