Skip to content

Instantly share code, notes, and snippets.

@joshnuss
Created September 12, 2014 18:37
Show Gist options
  • Save joshnuss/ea1dd8807120c835ca39 to your computer and use it in GitHub Desktop.
Save joshnuss/ea1dd8807120c835ca39 to your computer and use it in GitHub Desktop.
Angular Flash Service
angular.module('Foo').controller 'ExampleCtrl', ($scope, Flash) ->
$scope.doSomething = ->
Flash.info "Hello There!"
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
#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