简体   繁体   English

如果文件名相同,则更改事件功能对输入类型文件不起作用

[英]Change event function not working on input type file if file name is same

This is my html code to upload excel file 这是我上传excel文件的html代码

 <span class="control-fileupload" >
      <label for="file1" class="text-left">{{filePlaceHolder}}</label>
      <input type="file" id="file1" value="" (change)="openFile($event)" >
 </span>

But the problem is if i'm uploading same file twice the change function is not executing again because there is no change in input field. 但问题是,如果我两次上传相同的文件,则更改功能不会再次执行,因为输入字段没有变化。

Suppose i have uploaded abc.xls file once and there are some validation on this file and if i change the content of abc.xls and re upload it then change function is not re validating it again. 假设我已经上传了一次abc.xls文件,并且对此文件进行了一些验证,如果我更改了abc.xls的内容并重新上传它,那么更改函数不再重新验证它。

What changes i should make to work change function every time i upload a file whether file name is same or not. 每次上传文件时我应该对工作更改功能做出哪些更改,无论文件名是否相同。

I want to know how to write this click function in type script as i'm new to this. 我想知道如何在类型脚本中编写此单击函数,因为我是新手。

In angular 2 you can do it like this: 在角度2中你可以这样做:

<span class="control-fileupload" >
      <label for="file1" class="text-left">{{filePlaceHolder}}</label>
      <input #fileInput type="file" id="file1" (click)="fileInput.value = null" value="" (change)="openFile($event)" >
 </span>

This way every time you click on file input it will clear it's value so even if you select the same file change will fire. 这样,每次单击文件输入时,它都会清除它的值,因此即使您选择相同的文件,也会触发更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM