From be7a93d450205a7e9e2a1073e5de6972290d2478 Mon Sep 17 00:00:00 2001 From: Jad Salhani Date: Sat, 27 Jan 2018 22:05:10 +0200 Subject: [PATCH] added basic methods to wrap ionic AlertController --- src/providers/alert/alert.ts | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/providers/alert/alert.ts b/src/providers/alert/alert.ts index fae21c1..510dc28 100644 --- a/src/providers/alert/alert.ts +++ b/src/providers/alert/alert.ts @@ -1,5 +1,5 @@ -import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { AlertController } from 'ionic-angular/components/alert/alert-controller'; /* Generated class for the AlertProvider provider. @@ -10,8 +10,49 @@ import { Injectable } from '@angular/core'; @Injectable() export class AlertProvider { - constructor(public http: HttpClient) { - console.log('Hello AlertProvider Provider'); - } + constructor(private _alertCtrl: AlertController) { + } + + public showSuccessAlert(message: string): void { + let successAlert = this._alertCtrl.create({ + buttons: ["Ok"], + message: message, + enableBackdropDismiss: false, + title: "Success!" + }); + + successAlert.present(); + } + + public showErrorAlert(message: string): void { + let errorAlert = this._alertCtrl.create({ + buttons: ["Ok"], + message: message, + enableBackdropDismiss: false, + title: "Error!", + subTitle: "An error occurred" + }); + + errorAlert.present(); + } + + public showPrompt(message: string, confirmHandler: (value: any) => boolean | void, cancelHandler: (value: any) => boolean | void): void { + let promptAlert = this._alertCtrl.create({ + buttons: [{ + role: "confirm", + handler: confirmHandler, + text: "Confirm" + }, { + role: "cancel", + handler: cancelHandler, + text: "Cancel" + }], + message: message, + enableBackdropDismiss: false, + title: "Please confirm your action" + }); + + promptAlert.present(); + } }