Skip to content

Instantly share code, notes, and snippets.

@jbmyid
Created April 21, 2015 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbmyid/1bb7ce78e4931913704f to your computer and use it in GitHub Desktop.
Save jbmyid/1bb7ce78e4931913704f to your computer and use it in GitHub Desktop.
service for confirm alert etc
module.service("$nalerts", ["$q","$modal",'$rootScope', function($q, $modal,$rootScope){
var scope = $rootScope.$new();
var deferred;
var defaults = {title: "Alert", message: "", type: "info"};
var modal= $modal({scope: scope, template: 'cust_dialogs/nalerts.html', show: false});
scope.answer = function(res) {
deferred.resolve(res);
modal.hide();
}
var parentShow = modal.show;
var setOptions = function(opts){
scope.options = angular.extend({}, defaults, opts);
}
var open = function(){
deferred = $q.defer();
parentShow();
return deferred.promise;
}
var info = function(opts){
setOptions(opts);
scope.options.type = "info";
return open();
}
var warn = function(opts){
setOptions(opts);
scope.options.type = "warn";
return open();
}
var confirm = function(opts){
setOptions(opts);
scope.options.type = "confirm";
return open();
}
return {
info: info,
warn: warn,
confirm: confirm
};
}])
@jbmyid
Copy link
Author

jbmyid commented Apr 21, 2015

$nalerts.warn({message: "any message"}).then(function(res){ alert(res) })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment