...">

Typescript doesn't compile e.currentTarget.files

I have read with Jquery input files

<INPUT TYPE=FILE id="file" NAME="upfile" multiple>

      

With this code

$('#inputFile').on('change', 'body', (e) => {
  var files: any = e.currentTarget.files;  });

      

But typescript doesn't know that e.currentTarget has poperty files in this case. And give me a compile error.

How can I solve this problem?

Thank you in advance

+3


source to share


3 answers


$('#input-container').on('change', null, (e) => {
    var input = <HTMLInputElement>e.target;
    var files = input.files; //give you intellisense on files
});

      



+2


source


jQuery.On

has two different overloads (version 1.8). You are using the wrong overloaded method. Use correct

If you have no data to transfer, change your code to



$('#inputFile').on('change', 'body', null, (e) => {
var files: any = e.currentTarget.files;  });

      

+1


source


Similar to @ michael-tranchida, but I think a little cleaner:

export class Page {
    public fileToUpload:File = null;

    constructor(public fileInput: JQuery, public fileDetails: JQuery) {
        $(fileInput).on('change', (e) => {
            this.fileToUpload = <File>$(e.target).prop('files')[0];
            $(fileDetails).html(this.fileToUpload.name); // intellisense on fileToUpload
        });
    }
}

      

0


source







All Articles