import { Directive , Output , EventEmitter , HostListener , ElementRef } from '@angular/core' ; @ Directive ( { selector : '[dbl-click-copy]' , host : { title : 'Double click to copy to clipboard' } } ) export class DblClickCopyDirective { @ Output ( ) onCopy = new EventEmitter < Range > ( ) ; constructor ( private readonly element ) { } @ HostListener ( 'dblclick' ) onDblClick ( ) { const selection = getSelection ( ) ; const range = document . createRange ( ) ; range . selectNodeContents ( this . element . nativeElement ) ; selection . removeAllRanges ( ) ; selection . addRange ( range ) ; document . execCommand ( 'copy' ) ; this . onCopy . emit ( range ) ; } }