Home > Software design >  How to use Observables instead of Events to listen to dismiss event in Angular Ionic
How to use Observables instead of Events to listen to dismiss event in Angular Ionic

Time:12-29

I'm using ionic's inline modal, which's triggered by a boolean. However, when the modal is dismissed, the boolean is not automatically set to zero. According to ionic's documentation, "Developers should listen for the ionModalDidDismiss or didDismiss event and set isOpen to false. Unfortunately, they provide no further information on how to do so. Ionic had an Events module, but it was deprecated in exchange for using Observables. And now I'm stuck.

I tried to look for sources that explain how observables could be used in lieu of ionic's Events but to no avail. To summarize: I want to listen to a DOM dismiss event from ionic-modal and then set the isOpen boolean that triggers the modal to false. How can I use Observables to listen to events? What alternatives are there?

CodePudding user response:

I don't think you need to use observables, I think it's as simple as setting a variable to false:

<ion-modal (ionModalDidDismiss)="isModalOpen = false">
  ...
</ion-modal>
  • Related