Skip to content

Instantly share code, notes, and snippets.

@arnbak
Created September 25, 2013 09:42
Show Gist options
  • Select an option

  • Save arnbak/6697345 to your computer and use it in GitHub Desktop.

Select an option

Save arnbak/6697345 to your computer and use it in GitHub Desktop.
registerApp.service('alertService', function($rootScope, $timeout) {
var alertService = {};
$rootScope.alerts = [];
alertService.add = function(type, msg) {
$rootScope.alerts.push({'type': type, 'msg': msg, 'close': function() {
alertService.closeAlert(this);
}
});
//console.log("alert length " + $rootScope.alerts.length + " " + $rootScope.alerts[0].msg);
$timeout(function(){
alertService.closeAlert(this);
}, 15000);
};
alertService.closeAlert = function(alert) {
var index = $rootScope.alerts.indexOf(alert);
alertService.closeAlertIdx(index);
}
alertService.closeAlertIdx = function(index) {
$rootScope.alerts.splice(index, 1);
}
return alertService;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment