代码之家  ›  专栏  ›  技术社区  ›  Udara Abeythilake

如何修复离子输入类型文件中未定义的属性文件

  •  -1
  • Udara Abeythilake  · 技术社区  · 8 年前

    我正在开发离子3移动应用程序,我想将图像从移动应用程序上传到Web API。为此,我使用Post方法发送图像。我正在尝试将映像作为多部分文件上载,因为服务器需要多部分文件。因此,我添加了一个输入字段来选择文件,如。接下来,我创建了 changeListener() 事件将图像发送到服务器。

    <ion-input type="file" accept="image/*" id="upload" [(ngModel)]="imagePath" (ionChange)="changeListener($event)"></ion-input>
    
    
    changeListener($event): void {
         this.imagePath = $event.target.files[0];
         console.log($event.target.files[0])
         this.imageProvider.uploadImage(this.imagePath)
    }
    

    当我选择文件时,它会给我一个类型错误,比如“无法读取未定义的属性文件”。 有人能帮忙解决这个问题吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Sudarshana Dayananda    8 年前

    变化 ionChange 到 change .

    <ion-input type="file" accept="image/*" id="upload" 
            [(ngModel)]="imagePath" 
            (change)="changeListener($event)"></ion-input>
    

    Working example

    推荐文章