Below is the current function I am using to copy content to clipboard:
DEPRECATED CLICK FOR MORE INFORMATION
function copyToClipboardHelper(textToCopy: string) {
const textArea = document.createElement('textarea');
textArea.value = textToCopy;
// Prevent scrolling to bottom
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.position = 'fixed';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
let successfulCopy = false;
try {
successfulCopy = document.execCommand('copy');
} catch (error) {
console.error('Error copying content', error);
}
document.body.removeChild(textArea);
return !!successfulCopy;
}
HTML TEMPLATE
<div fxLayout="column" fxLayoutAlign="center start" fxFlex="70" class="">
<span>{{technicalSpecification.url}}</span>
</div>
<div fxLayout="column" fxLayoutAlign="center end" fxFlex="10">
<button mat-icon-button (click)="copyToClipboardHelper(technicalSpecification.url)">
<mat-icon matTooltip="Copy Service URL""> content_copy </mat-icon>
</button>
</div>