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

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

This is how my input tag looks like:


13条回答
  •  情深已故
    2020-12-12 15:24

    I am using a a very simple aproach. After a file has been uploaded, i shortly remove the input control, using *ngIf. That will cause the input field being removed from the dom and re-added, consequencely it is a new control, and therefore it is emply:

    showUploader: boolean = true;
    
    async upload($event) {
      await dosomethingwiththefile();
      this.showUploader = false;
      setTimeout(() =>{ this.showUploader = true }, 100);
    }

提交回复
热议问题