Unable to close Actionsheet that presents an Alert after clicked


#1

Hi,

One of my actionsheet handler creates an alert, but the actionsheet doesn’t close after the alert shows up. It’s a simple alert with an “OK” button. The use case is, I’m using the action sheet to post to an API endpoint when its clicked. When the API endpoint returns, I show an Alert with a “Thank you message”.

Preferably I’d like the ActionSheet to close even before the Alert message is shown.

Any idea how I can close the ActionSheet?

Here’s my implementation:

let actionSheet = ActionSheet.create({
      buttons: [
        {
          text: 'Report Abuse',
          role: 'destructive',
          handler: () => {
            let params = { resource_type: this.resourceType, resource_id: this.resourceId }
            this.authHttp.post(this.REPORT_URL, JSON.stringify(params)).toPromise()
              .then(res => {
                AlertService.alert({ nav: this.nav, message: "Thank you for your report. The administrators have been notified.", title: 'Thank You' })
              });
          }
        }, {
          text: 'Cancel',
          role: 'cancel',
          handler: () => {
            return true;
          }
        }
      ]
    });
    this.nav.present(actionSheet);

#2

I’m new to ionic, so take this with a grain of salt, but my guess would be you need to add:

return true;

at the end of your first button handler:

handler: () => {
let params = { resource_type: this.resourceType, resource_id: this.resourceId }
this.authHttp.post(this.REPORT_URL, JSON.stringify(params)).toPromise()
.then(res => {
AlertService.alert({ nav: this.nav, message: “Thank you for your report. The administrators have been notified.”, title: ‘Thank You’ })
});
return true;
}


#3

I’m not able to reproduce the problem you’re experiencing. I created a basic demo environment and it seems to work as expected. However, I don’t have the source code of the AlertService that’s why I used Alert.create() instead.

Could you please try to reproduce the problem in the plnkr demo environment?

And one more question - which release of Ionic are you using (beta.3 or earlier)?