Spilot
Spilot

Reputation: 1525

What method do I use to close a modal in angular 2?

I can open the modal just fine, but it isn't clear to me from any documentation whether there is a straight forward method to close the modal. I thought there was a dismiss method already on ModalController, but the log errors say otherwise. The ionic documentation isn't helpful enough. Does anyone know where else to point me?

import { ModalController, ViewController } from 'ionic-angular';

constructor(public modalCtrl: ModalController) {

 }

 Dismiss() {

   this.modalCtrl.dismiss();

 }

Upvotes: 0

Views: 693

Answers (2)

Suneet Bansal
Suneet Bansal

Reputation: 2702

Solution is attached below:

import { ModalController, ViewController } from 'ionic-angular';

constructor(public viewCtrl: ViewController) {

 }

 Dismiss() {
   this.viewCtrl.dismiss();
 }

Upvotes: 1

wannadream
wannadream

Reputation: 1760

This is from the doc.

The modal can later be closed or "dismissed" by using the ViewController's dismiss method.

https://ionicframework.com/docs/api/components/modal/ModalController/

Upvotes: 1

Related Questions