how to trigger click event of input file from button click in angular 2?

后端 未结 4 1254
一整个雨季
一整个雨季 2021-01-01 08:27



        
4条回答
  •  自闭症患者
    2021-01-01 09:07

    In Angular 4,

    HTML:

    
    
    

    Typescript:

    importFile(event) {
    
    if (event.target.files.length == 0) {
       console.log("No file selected!");
       return
    }
      let file: File = event.target.files[0];
      // after here 'file' can be accessed and used for further process
    }
    

    On considering the future issue of selecting same file not working, In input tag click event we are setting to null, which allows same file to select second time.

提交回复
热议问题