Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 component with clipboardData property

I have an Angular2 component with a method to paste data from the clipboard:

inputPaste(event){
  let clipboardData = event.clipboardData;
  ...

}

This way doesn't work for IE10+, but IE have a window object with a property clipboardData, but typescript compilator throws an error:

inputPaste(event){
  let clipboardData = event.clipboardData 
            || window.clipboardData; //error 'clipboardData' does not exist on type Windows
  ...

}

I have found a solution, that we must use angular2-clipboard directive, but I wan't to use it.

How can I use 'windows.clipboardData' in typescript?

like image 730
Alexander Surkov Avatar asked Sep 21 '16 13:09

Alexander Surkov


1 Answers

I have found a solution:

inputPaste(event){
    let clipboardData = event.clipboardData 
                        || (<any>window).clipboardData; //typecasting to any
                        or
                        || window['clipboardData']; //access like to array
    ...
}
like image 165
Alexander Surkov Avatar answered Oct 15 '22 22:10

Alexander Surkov