How to reset selected file with input tag file type in Angular 2?

前端 未结 13 1924
北恋
北恋 2020-12-12 14:56

This is how my input tag looks like:


13条回答
  •  醉话见心
    2020-12-12 15:07

    I typically reset my file input after capturing the selected files. No need to push a button, you have everything required in the $event object that you're passing to onChange:

    onChange(event) {
      // Get your files
      const files: FileList = event.target.files;
    
      // Clear the input
      event.srcElement.value = null;
    }
    

    Different workflow, but the OP doesn't mention pushing a button is a requirement...

提交回复
热议问题