Displays alerts and confirmation dialogs and toasts the easy way! 🚨
- Install
@webfactor/ionic-alert-service
via npm. - Add
AlertServiceModule.forRoot()
to your Ionic module imports.
This service epends on `@ngx-translate/core', which should be installed and implemented.
The dialogs expect the following translations. If not present, "Ok","Abbrechen","Löschen","Speichern" and "Verwerfen" are used.
{
"global": {
"ok": "Yep!",
"cancel": "Nope!",
"delete": "Löschen",
"save": "Speichern",
"dismiss": "Verwerfen"
}
}
alert(message: string, title: string = null, subTitle: string = null): Promise<any>
Presents an alert. The Promise is fulfilled when closing the dialog.
confirm(message: string, title: string = null, subTitle: string = null): Promise<any>
Presents an confirmation dialog. The Promise is fulfilled on accept, rejected on decline.
confirmDelete(message: string, title: string = null, subTitle: string = null): Promise<any>
Presents an confirmation dialog. The Promise is fulfilled on accept, rejected on decline. Replace translation cancel with delete
confirmSaveDismiss(message: string, title: string = null, subTitle: string = null): Promise<any>
Presents an confirmation dialog. The Promise is fulfilled on accept, rejected on decline. Replace translation ok with save and cancel with dismiss. enableBackdropDismiss option
shortToast(message: string, position: 'top' | 'middle' | 'bottom' = 'bottom'): Promise<any>
longToast(message: string, position: 'top' | 'middle' | 'bottom' = 'bottom'): Promise<any>
toastWithOptions(
message: string,
position: 'top' | 'middle' | 'bottom' = 'bottom',
duration: number = 2500,
showCloseButton: boolean = false,
closeButtonText: string = 'OK'
): Promise<any>
Presents a toast message.
The Promise is fulfilled when transition is completed.
constructor(private alertService: AlertService) {}
confirmPizzaOrder(): void {
this.alertService.confirm('Do you really want to order a triple cheese pizza?')
.then(() => {
// Pizza order confirmed.
}, err => {
// Pizza order cancelled.
});
}