Create a service to manage app alerts

Hi, thanks for your answer!

I created a service like the “PopupProvider” . This class loads the texts for the alerts and manages present and dismiss of the alerts.

For the specific cases were the alert button handler needs to call a Page local method, I did something based on this source: Return value from alert confirmation

@Injectable()
export class PopupProvider {
public alertExample: any;

presentAlertExample() {
this.alertExample = this.alertController.create( {
title, subtitle…
buttons [{

handler:() => {
this.alertExample.dismiss(“someValue”);
return false;
}
}]

 })

}
}

In the page code:

someFunction() {

}

callAlertProviderFunction() {
this.popupProvider.presentAlertExample();
this.popupProvider.alertExample.onDidDismiss(() => {
this.someFunction();
});
}

In short, I declare the on dismiss handler in the page code when I need to call a local function. It may not be ideal, but at least page logic stays in page classes and all the alert logic is in the provider.