我想触发/打开来自Ionic 4中另一页的文件输入 .
在第1页中,我有一个按钮可以转到模态,在页面模态中我想自动触发 <input file>
对话框
零件
ionViewWillEnter() {
document.getElementById('file').click(); // Tried with this one 1st, this only works in Internet Explorer / Edge
this.fileInput.nativeElement.click(); // And also this with @ViewChild
}
HTML
<input type="file" name="file" #file id="file" (change)="fileChange($event)" required>
4 回答
这是我用来触发<input> -element上的点击的代码:
改变这个:
对此:
我解决了它在page1中插入一个隐藏的输入文件,当用户试图转到page2时我触发了文件输入 .
当用户完成选择文件时,我将文件事件更改发送到第2页并管理第2页中的所有逻辑 .