[Ionic V4] How to use Modal Controller Events

I want to use the Events described in the documentation:
V4 Modal Documentation

I am on Angular 6 and can’t figure it out how to access them.

Calling them on the modal controller doesn’t work. Nor listening to the event of the host element.

@HostListener('ionModalDidPresent')
modalDidPresent(event) {
  console.log('Did present');
}

So how should it be done?
Huge thanks in advance!

1 Like

Two guesses (untested)

Use angular event binding in the html template where u create the modal using tags:(ionModalDidPresent)=“whateverfunction()”

Or use the create method and the resulting variable points to the modal conponent which holds ionModalDidPresent which is of type eventemitter and hence you can subscribe to: https://github.com/ionic-team/ionic/blob/master/core/src/components/modal/modal.tsx

  async presentModal() {
    const modal = await this.modalController.create({
      component: AddTaskModalComponent,
      componentProps: { value: 123, next: "foo" }
    });

    // handle "onDidDismiss"
    modal.onDidDismiss().then((d: any) => this.handleModalDismiss(d));

    return await modal.present();
  }