Typescript Error: Property 'files' does not exist on type 'HTMLElement'

廉价感情. 提交于 2020-01-02 02:28:09

问题


I wish to create an upload function for my Apps by using IONIC.

Here is my HTML code:

<input ion-button block type="file" id="uploadBR">
<input ion-button block type="file" id="uploadIC">
<button ion-button block (click)="upload()">Confirm Claim Restaurant</button>

Here is my upload() function:

upload(){   
   let BR = document.getElementById('uploadBR').files[0]
   let IC = document.getElementById('uploadIC').files[0]
   console.log(BR)
   console.log(IC)    
 }

In normal HTML it should work, but it doesn't work with my IONIC.

When building the App, it will show the error Typescript Error: Property 'files' does not exist on type 'HTMLElement'.

Am i do it in wrong way or it has to be done in different way with typescript?

Thanks.


回答1:


You neet to cast it as a HTMLInputElement as files is a property of input element

let BR = (<HTMLInputElement>document.getElementById('uploadBR')).files[0];


来源:https://stackoverflow.com/questions/49827325/typescript-error-property-files-does-not-exist-on-type-htmlelement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!