Skip to content

Instantly share code, notes, and snippets.

@blackfyre
Last active January 12, 2016 08:23
Show Gist options
  • Save blackfyre/ca5178650dfd15d08da0 to your computer and use it in GitHub Desktop.
Save blackfyre/ca5178650dfd15d08da0 to your computer and use it in GitHub Desktop.
sweetAlert Angular.js service example
/* Create the sweetAlert Service singleton */
function sweetAlertService() {
this.success = function(title, message) {
swal(title, message,'success');
};
this.error = function(title, message) {
swal(title, message,'error');
};
this.warning = function(title, message) {
swal(title, message,'warning');
};
this.info = function(title, message) {
swal(title, message,'info');
};
this.custom = function (configObject) {
swal(configObject);
}
};
/* Create our angular app */
var angularApp = angular.module('angularApp', []);
/* add the service and the controller */
angularApp
.service('swal', sweetAlertService)
.controller('QuizCtrl', function ($scope, sweetAlert) {
/* and now we can use sweet alert */
swal.info("Oops...", "Something went wrong!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment