Trigger input file click in Ionic 4 after page change

I want to trigger/open a file input coming from another page in Ionic 4.

In page 1 I have a button to go to page 2 with params, in page two I get the param so I want to automatically trigger the <input file> dialog that I have in page two.


ionViewWillEnter() {
    document.getElementById('file').click(); // Tried with this one 1st;    // And also this with @ViewChild


<input type="file" name="file" #fileInput id="file" (change)="fileChange($event)" required>

I tried with both of these too but no luck:

@ViewChild('file') fileInput:ElementRef;
@ViewChild('file') fileInput:any;

I’m still having this issue. My topic in

What does this mean? Are you using navparams? Your ionViewWillEnter code looks wrong to me, but I don’t know what you are trying to do, so I can’t suggest how to correct it.

I’m using navparams, but that doesn’t matter as I can’t achieve to open the file input programmatically .

ionViewDidLoad() {
    if ( == true) { // works
     // Reach here but input file doesnt show up
        document.getElementById('file').click(); // doesn't work

What do you mean by Ionic 4? And how do you transition from page 1 to page 2?

I’m using Ionic 4 version, it’s ionic2 core concept.
I transition with this.navCtrl.push('Page2', {test: true}); This works, it’s the input that doesn’t, forget about the transition between pages as I can open the file input in the same page programmatically

I’m so confused. Why don’t you just put the input in your navParams?

Do you mean when user push the button [go to page 2] it should be an input? I don’t know how to achieve that and the input file is in page2.html

My objective is very simple, show the native explorer programmatically so the user can select a file. I want to open the dialog of the file input

Example, I want to trigger the button of the input file ‘Click me’.

Oh I see. You’re going to have to rethink your design. You’re asking for an experimental technology that isn’t supported on mobile.