Created
September 12, 2014 18:37
-
-
Save joshnuss/ea1dd8807120c835ca39 to your computer and use it in GitHub Desktop.
Angular Flash Service
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
angular.module('Foo').controller 'ExampleCtrl', ($scope, Flash) -> | |
$scope.doSomething = -> | |
Flash.info "Hello There!" |
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
angular.module('Flash', []).factory 'Flash', ($timeout) -> | |
messages: [] | |
add: (type, message) -> | |
flash = type: type, text: message | |
@messages.push(flash) | |
@timeout(flash) | |
timeout: (flash) -> | |
self = this | |
$timeout((-> self.remove(flash)), 2500) | |
success: (message) -> @add('success', message) | |
info: (message) -> @add('info', message) | |
error: (message) -> @add('error', message) | |
remove: (flash) -> | |
@messages = @messages.filter (x) -> x != flash | |
hasMessages: () -> | |
@messages.length > 0 |
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
#flash-messages.container | |
.alert(ng-repeat="message in flash.messages" class="alert-{{message.type}}" role="alert") | |
button.close(data-dismiss="alert") × | |
.text | |
p(ng-bind="message.text") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment