Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: modalController.dismiss () does not close the modal if several modals are created but not presented. #21173

Closed
Lougnar opened this issue Apr 30, 2020 · 2 comments

Comments

@Lougnar
Copy link

Lougnar commented Apr 30, 2020

Bug Report

Ionic version:
[x] 5.0.7 ionic-angular

Current behavior:

When i create multiple modals using modalController's create function, and do not present all of the modal. The modalController's dismiss function does not close any modals.

Expected behavior:
The modal should be dismissed

Steps to reproduce:

  1. create several modals and present one
   const modal = await this.modalController.create({ 
      component: ModalComponentComponent
    });
    const modal2 = await this.modalController.create({ 
      component: ModalComponentComponent
    });
    const modal3 = await this.modalController.create({ 
      component: ModalComponentComponent
    });
    modal.present();
  1. try to close the modal presented within it's component
    modal-components.ts
dismiss() {
    this.modaleController.dismiss();
  }

modal-component.html

<ion-button (click)="dismiss()"> close modale </ion-button>

A sample application StackBlitz:
https://stackblitz.com/edit/angular-pmzd2p

@liamdebeasi
Copy link
Contributor

Thanks for the issue. I am going to close this as this is not a bug in Ionic Framework. By default, the modal controller attempts to close the most recently created modal. In this case, that is modal3.

It sounds like you want to dismiss modal, in which case you can either call the dismiss method on the modal itself, or create the modal with an ID and pass that ID into the modal controller dismiss method.

For example:

const modal = await this.modalController.create({ 
  component: ModalComponentComponent,
  id: 'my-modal-id'
});

...

this.modalController.dismiss(undefined, undefined, 'my-modal-id);
// the other parameters allow you to specify a data object to return and a role but are both optional

@ionitron-bot
Copy link

ionitron-bot bot commented May 30, 2020

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators May 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants