I am trying to fire onchange
event everytime a file is selected. It does fire if the file I select is different, however, I wanted to fire even if the same file is selected twice.
html
<input name="file" type="file" (change)="onChange($event)" style="width:80%" />
component
onChange(event: any) { let files = event.srcElement.files; this.files = files; event= null; }
The most reliable way to achieve this cross browser and without having to change much code is to set the value of the input to null on click.
onclick="this.value = null"
So your input would look like this
<input name="file" type="file" onclick="this.value = null" (change)="onChange($event)" style="width:80%"/>
Here is an working example: plnkr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With