Input file sharing event does not fire

I try to fire the onchange event every time a file is selected. It works if the file I selected is different, however, I would like to run it even if the same file is selected twice.

HTML

<input name="file" type="file" (change)="onChange($event)" style="width:80%" /> 

component

 onChange(event: any) { var files = event.srcElement.files; this.files = files; event= null; } 
+5
angular
source share
1 answer

The most reliable way to achieve this cross-browser and without having to change the code is to set the input value to null when clicked.

 onclick="this.value = null" 

So your entry will look like this

 <input name="file" type="file" onclick="this.value = null" (change)="onChange($event)" style="width:80%"/> 

Here is a working example: plnkr

+5
source share

All Articles