angular copy to clipboard code example
Example 1: ionic copy to clipboard
import { Clipboard } from '@ionic-native/clipboard/ngx';
constructor(private clipboard: Clipboard) { }
...
this.clipboard.copy('Hello world');
Example 2: copy to clipboard angular
navigator.clipboard.writeText(content).then().catch(e => console.error(e));
Example 3: angular how to copy text with button
copyToClipboard(item): void {
let listener = (e: ClipboardEvent) => {
e.clipboardData.setData('text/plain', (item));
e.preventDefault();
};
document.addEventListener('copy', listener);
document.execCommand('copy');
document.removeEventListener('copy', listener);
}