how to trigger event click at input type=“file” by function in angular 2?

前端 未结 2 1725
失恋的感觉
失恋的感觉 2021-01-18 01:33

I have this code in Html file .


demo.ts

import {
  Component,
           


        
相关标签:
2条回答
  • 2021-01-18 02:18

    No need to write code in controller

    <input #fileInput type="file"  />
    <button type="button" (click)="fileInput.click()">trigger</button>
    
    0 讨论(0)
  • 2021-01-18 02:30

    Pass the fileInput reference to triggerFile() and do the fileInput.click() there instead:

    <input #fileInput type="file"  />
    <button type="button" (click)="triggerFile(fileInput)">trigger</button>
    
    triggerFile(fileInput:Element) {
      // do something
      fileInput.click();
    }
    
    0 讨论(0)
提交回复
热议问题