flex copy directive

This commit is contained in:
Kyle Spearrin 2019-01-23 16:22:38 -05:00
parent 6dc44c0885
commit 09df62db4c
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
import {
Directive,
ElementRef,
HostListener,
} from '@angular/core';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
@Directive({
selector: '[appFlexCopy]',
})
export class FlexCopyDirective {
constructor(private el: ElementRef, private platformUtilsService: PlatformUtilsService) { }
@HostListener('copy') onCopy() {
if (window == null) {
return;
}
let copyText = '';
const selection = window.getSelection();
for (let i = 0; i < selection.rangeCount; i++) {
const range = selection.getRangeAt(i);
const text = range.toString();
copyText += text;
}
this.platformUtilsService.copyToClipboard(copyText, { window: window });
}
}