Skip to content

Commit

Permalink
added basic methods to wrap ionic AlertController
Browse files Browse the repository at this point in the history
  • Loading branch information
jadsalhani committed Jan 27, 2018
1 parent 159bb8e commit be7a93d
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions src/providers/alert/alert.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();
}

}

0 comments on commit be7a93d

Please sign in to comment.