Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面更改后,在Ionic 4中单击触发输入文件_Javascript_Html_Angular_Ionic Framework - Fatal编程技术网

Javascript 页面更改后,在Ionic 4中单击触发输入文件

Javascript 页面更改后,在Ionic 4中单击触发输入文件,javascript,html,angular,ionic-framework,Javascript,Html,Angular,Ionic Framework,我想触发/打开来自Ionic 4中另一页的文件输入 在第1页中,我有一个按钮可以转到模式,在页面模式中,我想自动触发对话框 组成部分 ionViewWillEnter() { document.getElementById('file').click(); // Tried with this one 1st, this only works in Internet Explorer / Edge this.fileInput.nativeElement.click();

我想触发/打开来自Ionic 4中另一页的文件输入

在第1页中,我有一个按钮可以转到模式,在页面模式中,我想自动触发
对话框

组成部分

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


这是我用来触发点击-元素的代码:

@ViewChild("file") fileInput: ElementRef;

triggerClick() {
    let event = new MouseEvent('click', {bubbles: true});
    this.renderer.invokeElementMethod(this.fileInput.nativeElement, 'dispatchEvent', [event]);
}
更改此项:

ionViewWillEnter() {
    document.getElementById('file').click(); // Tried with this one 1st
    this.fileInput.nativeElement.click();    // And also this with @ViewChild
}
为此:

ionViewDidLoad() {
    document.getElementById('file').click(); // Tried with this one 1st
}
尝试在 组件的视图已完全初始化


我解决了在第1页插入一个隐藏的输入文件的问题,当用户试图转到第2页时,我触发文件输入


当用户选择完文件后,我将文件事件更改发送到第2页,并管理第2页中的所有逻辑。

既不工作也不出错。事件和文件输入的控制台日志
MouseEvent{isTrusted:false,screenX:0,screenY:0,clientX:0,clientY:0,…}
不起作用,还尝试了设置超时200ms
控制台。log
文档.getElementById('file')
这只适用于Internet Explorer/Edge,不适用于Chrome。在Ionic中,这也是生命周期
构造函数-->ionViewDidLoad-->ionViewWillEnter-->ionViewDidEnter-->ionViewWillLeave-->ionViewDidLeave-->ionViewWillUnload
@Chumill,因为它可以在chrome和android设备上运行。我在两个站台都检查过了。你可以。而爱奥尼亚是建立在angular上的,所以爱奥尼亚也支持angular生命周期挂钩。你能给我举一个不按任何按钮就自动打开输入文件的例子吗?只需使用从页面A到页面B的导航打开输入文件,您就可以使用从一个页面到另一个页面的导航自动打开输入文件。但我认为chrome有一个bug,因为第一次当第二个页面加载时,输入文件对话框并没有打开,但在关闭和重新打开时,它工作得非常好。这种方法在和上非常有效。它在Edge上有效,但在Chrome上不起作用。我在第一次尝试时正在寻找一种Chrome的解决方案。另外,您提供的解决方案已经是这个问题的重复答案。但在问题中,您要求您要在模态中而不是在第一页中触发方法。是的,我想在看到第2页/模态页面之前打开文件资源管理器。
ionViewDidLoad() {
    document.getElementById('file').click(); // Tried with this one 1st
}
ngAfterViewInit() {
    document.getElementById('file').click();
}