Created
April 21, 2015 13:47
-
-
Save jbmyid/1bb7ce78e4931913704f to your computer and use it in GitHub Desktop.
service for confirm alert etc
This file contains hidden or 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
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 | |
}; | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$nalerts.warn({message: "any message"}).then(function(res){ alert(res) })