打字稿错误:类型"HTMLElement"上不存在属性“文件" [英] Typescript Error: Property 'files' does not exist on type 'HTMLElement'

查看:773
本文介绍了打字稿错误:类型"HTMLElement"上不存在属性“文件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用IONIC为我的应用创建上传功能.

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

这是我的HTML代码:

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>

这是我的upload()函数:

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

在正常的HTML中,它应该可以工作,但不能与我的IONIC一起工作.

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

在构建应用程序时,它将显示错误Typescript Error: Property 'files' does not exist on type 'HTMLElement'.

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?

谢谢.

推荐答案

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

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

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

这篇关于打字稿错误:类型"HTMLElement"上不存在属性“文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆