How to close modal page from app.component.ts?

How to close an modal page from app.component.ts class using nav controller? I was trying methods like popToRoot() but it doesn’t work.

I would like to know how to do this too - did you get anywhere?

Modals are closed by injecting a ViewController into the modal then calling dismiss on it. If you inject it as public you should be able to just call it by access your modal in your component and doing myModal.viewController.dismiss();

Haven’t tested it but…it should work.

Depending on your version of Ionic you might also be able to do myModal.getImplementation().dismiss();.

1 Like

i don’t have access to myModal at this point, i want to close “current page”

ok here is the solution:

Another potential solution is using a QueryList. I’m not 100% on where you’re trying to access Modal from,
but

import { QueryList, ViewChild } from '@angular/core';
import { Modal } from 'ionic-angular';

export class AccessPage {
 @ViewChild(Modal) myModal: QueryList<Modal>;
 /* or @ViewChildren(Modal) myModals: QueryList<Modal>; */
}

might be a useful approach.
It 's possible that ViewChild needs to be replaced with ViewChildren and @ViewChild replaced with @ViewChildren as well.