Property 'files' does not exist on type 'EventTarget' error in typescript

后端 未结 7 750
迷失自我
迷失自我 2020-11-30 09:50

I am trying to access the value of the input file from my ionic 2 application but still I\'m facing the issue of property files does not exist on type \'EventTarget\'. As it

7条回答
  •  误落风尘
    2020-11-30 10:16

    You can cast it as a HTMLInputElement:

    document.getElementById("customimage").onchange = function(e: Event) {
        let file = (e.target).files[0];
        // rest of your code...
    }
    

    Update:

    You can also use this:

    let file = (e.target as HTMLInputElement).files[0];
    

提交回复
热议问题