Skip to content

Instantly share code, notes, and snippets.

@zmnv
Created March 3, 2019 11:38
Show Gist options
  • Save zmnv/c5f0febbf25bda5b484724023ab78147 to your computer and use it in GitHub Desktop.
Save zmnv/c5f0febbf25bda5b484724023ab78147 to your computer and use it in GitHub Desktop.
Paste events listener Angular 6
@HostListener('document:keydown', ['$event']) handleKeyboardEvent(event: KeyboardEvent) {
if ((event.ctrlKey || event.metaKey) && event.keyCode === 86) {
console.log('CTRL + V', event);
}
}
@HostListener('paste', ['$event']) onPaste(e: any) {
const items = e.clipboardData.items;
let blob = null;
for (const item of items) {
if (item.type.indexOf('image') === 0) {
blob = item.getAsFile();
}
}
if (blob !== null) {
const fileName = dateSnapshoot();
const fileFromBlob: File = new File([blob], `${fileName}.jpg`);
this.uploader.addToQueue(new Array<File>(fileFromBlob));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment