After modal dismissed the injected service is undefined


#1

I’m using Ionic 2 and have a page that calls a modal to confirm the users response. I have successfully been able to pass data to and from the modal but now I’m realizing that the service that I have being injected from the calling page is now undefined. NgInit is not being called nor the constructor of the calling page is being called a second time so I am completely stumped why it is now undefined. I’m curious if this is a bug or if I’m just completely going about this the wrong way.

Any advice?

Here’s the relevant code:

  private openConfirmModal(confirmModalInputModel: ConfirmModalInputModel) {
    this._modal = this._modalController.create(ConfirmModalComponent, { ConfirmModalInputModel: confirmModalInputModel });
    this._modal.onDidDismiss(this.modalOnDidDismiss);
    this._modal.present();
  }
 
  private modalOnDidDismiss(confirmModalOutputModel: ConfirmModalOutputModel) {
    if (confirmModalOutputModel.confirmed) {
      if (confirmModalOutputModel.choice == "Approve") {
        console.log("choice Reject"); 
        console.log(this._capitalRequestService);       
      }
      else if (confirmModalOutputModel.choice == "Reject") {
        console.log("choice Reject"); 
      }
    }
  }

#2

I figured it out in case anyone else is stumped. I changed this line:
this._modal.onDidDismiss(this.modalOnDidDismiss);

to this:
this._modal.onDidDismiss(output => this.modalOnDidDismiss(output));