angular - 如何修复离子输入类型文件中未定义的属性文件
问题描述
我正在开发 Ionic 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)
}
当我选择文件时,它给了我一个 typeError,例如“无法读取未定义的属性文件”。任何人都可以帮助解决这个问题吗?
解决方案
更改ionChange
为change
。
<ion-input type="file" accept="image/*" id="upload"
[(ngModel)]="imagePath"
(change)="changeListener($event)"></ion-input>
推荐阅读
- c# - 如何将类似对象的json对象反序列化为c#列表
- django - Django ORM - 获取早于记录的“持续时间”天的记录
- mongodb - com.mongodb.MongoSocketOpenException:连接到 mongodb docker 容器时
- perl - 如何比较嵌套哈希
- bash - 如何命令 curl 下载到 stderr
- vba - 如何在 VB 中处理此运行时类型不匹配错误?
- c - 如何将反向字符串函数从主函数转换为自己的独立函数?
- git - 如何使用 diff-cover 针对分支的特定提交 ID 生成覆盖率报告?
- java - 有没有办法以编程方式定义 MToolbarElements 在 MToolBar 中的位置?
- php - Nova actionable_id 不能为空