Last active
January 12, 2016 08:23
-
-
Save blackfyre/ca5178650dfd15d08da0 to your computer and use it in GitHub Desktop.
sweetAlert Angular.js service example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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