简体   繁体   English

打字稿错误:'HTMLElement'类型中不存在属性'文件'

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

I wish to create an upload function for my Apps by using IONIC. 我希望使用IONIC为我的应用程序创建上传功能。

Here is my HTML code: 这是我的HTML代码:

<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()函数:

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. 在普通的HTML中它应该可以工作,但它不适用于我的IONIC。

When building the App, it will show the error Typescript Error: Property 'files' does not exist on type 'HTMLElement'. 构建应用程序时,它将显示错误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. 谢谢。

您需要将其转换为HTMLInputElement,因为filesinput元素的属性

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Typescript:属性“数据”在HTMLElement类型上不存在 - Typescript : Property 'data' dose not exist on type HTMLElement 错误:类型“ JQuery”上不存在“可拖动”属性 <HTMLElement> “ - Error: Property 'draggable' does not exist on type 'JQuery<HTMLElement>' 错误TS2339:类型“ HTMLElement”上不存在属性“名称” - error TS2339: Property 'name' does not exist on type 'HTMLElement' 打字稿中的类型“EventTarget”错误中不存在属性“文件” - Property 'files' does not exist on type 'EventTarget' error in typescript 类型“HTMLElement”角度 4 上不存在“已检查”属性 - Property 'checked' does not exist on type 'HTMLElement' angular 4 类型“JQuery”上不存在属性“掩码”<HTMLElement> - Property 'mask' does not exist on type 'JQuery<HTMLElement> 类型“ HTMLElement”上不存在属性“ pseudoStyle” - Property 'pseudoStyle' does not exist on type 'HTMLElement' 类型&#39;HTMLElement&#39;上不存在属性&#39;toDataURL&#39; - Property 'toDataURL' does not exist on type 'HTMLElement' 类型“JQuery”上不存在属性“slick”<HTMLElement> &#39; - Property 'slick' does not exist on type 'JQuery<HTMLElement>' 类型&#39;HTMLElement&#39;上不存在属性&#39;contentDocument&#39; - Property 'contentDocument' does not exist on type 'HTMLElement'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM