Created
September 25, 2013 09:42
-
-
Save arnbak/6697345 to your computer and use it in GitHub Desktop.
Revisions
-
arnbak created this gist
Sep 25, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ 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; });