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

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

This is how my input tag looks like:


13条回答
  •  孤城傲影
    2020-12-12 15:21

    Short version Plunker:

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'my-app',
      template: `
          
          
      `
    })
    export class AppComponent {
    
    
    }
    

    And i think more common case is to not using button but do reset automatically. Angular Template statements support chaining expressions so Plunker:

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'my-app',
      template: `
          
      `
    })
    export class AppComponent {
    
      onChange(files, event) {
        alert( files );
        alert( event.target.files[0].name );
      }
    
    }
    

    And interesting link about why there is no recursion on value change.

提交回复
热议问题