I'm trying to access data from the clipboard in TS1.6 using the following:
$(container).bind("paste", (e) => {
var data = e.originalEvent.clipboardData.getData('text');
});
But it just gives me the following build error:
Property 'clipboardData' does not exist on type 'JQueryEventObject'
If I remove the 2nd line and debug it in Chrome 46, I can get at the clipboard data just by calling
e.originalEvent.clipboardData.getData('text');
I can't see clipboardData in the JQueryEventObject interface in the latest version of jQuery.d.ts but the question is - should it be there or is there a different way of retrieving data from the clipboard that TS currently supports?
Use ClipboardEvent type (e.g.)
private onPaste(event: ClipboardEvent) {
const {clipboardData} = event;
const pastedText = clipboardData.getData('text');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With