Created
March 3, 2019 11:38
-
-
Save zmnv/c5f0febbf25bda5b484724023ab78147 to your computer and use it in GitHub Desktop.
Paste events listener Angular 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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