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

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

This is how my input tag looks like:


13条回答
  •  青春惊慌失措
    2020-12-12 15:23

    One way to achieve it is to wrap your input in

    tag and reset it.

    I'm not considering attaching thr form to NgForm or FormControl either.

    @Component({
      selector: 'form-component',
      template: `
        
          
        
        
    `
    })
    class FormComponent {
    
    
    
      @ViewChild('form') form;
    
    
      reset() {
        this.form.nativeElement.reset()
      }
    }
    

    https://plnkr.co/edit/Ulqh2l093LV6GlQWKkUA?p=preview

提交回复
热议问题