【问题标题】:Typescript Error: Property 'files' does not exist on type 'HTMLElement'打字稿错误:“HTMLElement”类型上不存在属性“文件”
【发布时间】:2018-04-14 02:33:23
【问题描述】:

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

这是我的 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>

这是我的upload() 函数:

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

在普通的 HTML 中它应该可以工作,但它不适用于我的 IONIC。

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

是我做错了还是必须用打字稿以不同的方式做?

谢谢。

【问题讨论】:

    标签: angular typescript ionic-framework


    【解决方案1】:

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

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

    【讨论】:

    • 正是我想要的。谢谢。
    猜你喜欢
    • 2017-11-25
    • 1970-01-01
    • 2018-09-27
    • 2017-03-26
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 2018-11-30
    • 2018-09-29
    相关资源
    最近更新 更多