【问题标题】:Browse the same file again and again in html在 html 中一次又一次地浏览同一个文件
【发布时间】:2017-11-24 21:15:20
【问题描述】:

我的 html 上有以下代码

<input type="file"  style="display: none" #file(change)="processImage($event)" />
<button type="button"  class="btn" (click)="file.click()"  Browse </button>

我从桌面选择 image1,它由processImage() 加载到 html 上,然后我用删除按钮将其删除。然后我再次浏览并再次选择 image1 但没有任何反应,当我选择 image2 时,它被加载,然后我选择 image1 又是加载。总之,再次选择相同的图像没有任何作用,可能不是更改事件。这也是有道理的。但是由于某种原因,用户可能会在加载和删除后一次又一次地加载它。

我如何显示图像:

<div *ngIf="isImageLoaded" class="showImg"><img [src]="myImage"></div>

任何提示可以加载相同的图像并触发processImage()

【问题讨论】:

  • 在显示图像的位置显示代码,并在删除图像时将空值设置为文件输入
  • 我添加了代码实际上我想在每个图像加载时调用 processImage() 即使它是同一个图像。
  • 你能展示delete()方法吗?

标签: html angular typescript


【解决方案1】:

您必须清除event.currentTarget.value,如下所示,我在本地尝试过,效果很好。每当您选择任何图像时,即使它重复总是触发processImage 方法。

public processImage(event:any):void{
     //your logic    
     event.currentTarget.value='';
}

【讨论】:

  • 非常感谢,这么简单又贴心的解决方案。
猜你喜欢
  • 2023-04-06
  • 2013-05-24
  • 1970-01-01
  • 2020-03-24
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2016-09-12
  • 1970-01-01
相关资源
最近更新 更多