加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 使用ngModel访问输入文件[]

发布时间:2020-12-17 17:02:15 所属栏目:安全 来源:网络整理
导读:我的表单中有一个图片上传输入: input type="file" [(ngModel)]="item.image" name="image" #image 是否可以使用item.image ngModel访问#image.files [0](而不是创建引用)? 如果没有,当输入类型是文件时,ngModel仍然存储什么? 解决方法 Is it possible to
我的表单中有一个图片上传输入:

<input type="file" [(ngModel)]="item.image" name="image" #image>

是否可以使用item.image ngModel访问#image.files [0](而不是创建引用)?

如果没有,当输入类型是文件时,ngModel仍然存储什么?

解决方法

Is it possible to access #image.files[0] using item.image ngModel (instead of creating a reference)?

是的,您可以订阅输入的更改事件并将文件传递给方法:

<input type="file" name="image" (change)="fileSelected($event.target.files[0])" />

What does ngModel stores anyway when the input type is file?

没有. DefaultValueAccessor 不能用于输入[type =“file”],我认为此刻它没有特定的值访问器.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读