Search code examples
angularfile-upload

How to set event listener while choosing a file other that (change) event in Angular


I'm trying to set a popup validation for my file upload and now i am using (change)=method($event) as the event listener, the problem here is its only triggering when the input file changes its not triggering when I choose same file next time,How to solve this?

<input #inputFile type="file" name="uploadFile" (change)="fileInputChange($event,docu.id,inputFile)" />


Solution

  • While I see no reason to retrigger the popup validation on selecting the same file, since nothing really changed and validation will return the same, you can add this to the input element in html:

    (click)="$event.target.value=null"

    It will actually remove the input's value when user clicks the input element, and the change event will, thus, always treat the selected file as new.