Created
July 31, 2013 10:51
-
-
Save jhiemer/6121096 to your computer and use it in GitHub Desktop.
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
var alertChannel = "alertChannel"; | |
$scope.alerts = []; | |
$rootScope.$on(alertChannel, function(event, data) { | |
$scope.alerts.push(data); | |
$timeout(function(data) { | |
if ($scope.alerts.length > 0) { | |
$scope.closeAlert(0); | |
} | |
}, timeout); | |
}); | |
$scope.closeAlert = function(index) { | |
$scope.alerts.splice(index, 1); | |
}; | |
$scope.msg = function(type) { | |
messageEmitter.message('Message', 'Please check the message below!', type); | |
}; |
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
<div class="container-fluid" ng-controller="alertController" style="padding-top: 60px"> | |
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)"> | |
<h4 class="alert-heading">{{alert.title}}</h4> | |
<p>{{alert.msg}}<p> | |
</alert> | |
</div> |
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
var service = function($rootScope) { | |
var alertChannel = 'alertChannel'; | |
var message = {}; | |
var messageEmitter = { | |
message : function(title, msg, type) { | |
message = { | |
title : title, | |
msg : msg, | |
type : type | |
} | |
$rootScope.$broadcast(alertChannel, message); | |
} | |
}; | |
return messageEmitter; | |
} | |
service.$inject = ['$rootScope']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment