如何触发角2中的按钮点击输入文件的点击事件? [英] how to trigger click event of input file from button click in angular 2?
本文介绍了如何触发角2中的按钮点击输入文件的点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< input type =fileaccept =image / *>< button>上载档案< / button>
如何从Angular 2中的按钮的点击事件触发输入类型=文件的点击事件? 你可以像下面这样利用模板引用变量:
$ b解决方案$ b
< input type =fileaccept =image / *#file>
< button(click)=file.click()>上传文件< / button>
相应的plunkr在这里 https://plnkr.co/edit/JB4HY0oxEUgXXIht2wAv?p=preview
<input type="file" accept="image/*"> <button>Upload file</button>
How to trigger click event of input type=file from button's click event in Angular 2?
解决方案You can leverage template reference variable as follows:
<input type="file" accept="image/*" #file> <button (click)="file.click()">Upload file</button>
The corresponding plunkr is here https://plnkr.co/edit/JB4HY0oxEUgXXIht2wAv?p=preview
这篇关于如何触发角2中的按钮点击输入文件的点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文