flash.service.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (function() {
  2. 'use strict';
  3. angular
  4. .module('cloudbudget')
  5. .factory('FlashService', FlashService);
  6. FlashService.$inject = ['$rootScope', 'growl'];
  7. function FlashService($rootScope, growl) {
  8. var service = {};
  9. service.success = success;
  10. service.error = error;
  11. initService();
  12. return service;
  13. function initService() {
  14. $rootScope.$on('$locationChangeStart', function() {
  15. clearFlashMessage();
  16. });
  17. function clearFlashMessage() {
  18. var flash = $rootScope.flash;
  19. if( flash ) {
  20. if( !flash.keepAfterLocationChange ) {
  21. delete $rootScope.flash;
  22. } else {
  23. flash.keepAfterLocationChange = false;
  24. }
  25. }
  26. }
  27. }
  28. function success(message, keepAfterLocationChange) {
  29. growl.success(message,{title: 'Success!'});
  30. }
  31. function error(message, keepAfterLocationChange) {
  32. growl.error(message, {title: 'Error!'});
  33. }
  34. }
  35. })();