Created
November 19, 2015 15:11
-
-
Save mgosk/59addf01d47c04136e0e to your computer and use it in GitHub Desktop.
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 characters
(function () { | |
'use strict'; | |
angular.module('thx4showApp') | |
.controller('alerts.flashCtrl', ['$flash', function ($flash) { | |
var vm = this; | |
vm.service = $flash; | |
}]); | |
})(); |
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 characters
//http://fdietz.github.io/recipes-with-angular-js/common-user-interface-patterns/displaying-a-flash-notice-failure-message.html | |
(function () { | |
'use strict'; | |
angular.module('thx4showApp') | |
.service('$flash', ['$rootScope', function ($rootScope) { | |
var errorQueue = []; | |
var successQueue = []; | |
var currentError; | |
var currentSuccess; | |
$rootScope.$on('$stateChangeStart', function (event, toState) { | |
currentError = errorQueue.shift() || undefined; | |
currentSuccess = successQueue.shift() || undefined; | |
}); | |
return { | |
setError: function (message) { | |
errorQueue.push(message); | |
}, | |
getError: function () { | |
return currentError; | |
}, | |
checkError: function () { | |
return currentError !== undefined; | |
}, | |
setSuccess: function (message) { | |
successQueue.push(message); | |
}, | |
getSuccess: function () { | |
return currentSuccess; | |
}, | |
checkSuccess: function () { | |
return currentSuccess !== undefined; | |
} | |
}; | |
}]); | |
})(); |
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 characters
<div ng-controller="alerts.flashCtrl as flash"> | |
<div ng-if="flash.service.checkSuccess()" class="well successBox"> | |
<h2 translate="{{flash.service.getSuccess()}}"></h2> | |
</div> | |
<div ng-if="flash.service.checkError()" class="well errorBox"> | |
<h2 translate="{{flash.service.getError()}}"></h2> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment