diff --git a/src/growlFactory.js b/src/growlFactory.js index d3e5329..ed6e64c 100644 --- a/src/growlFactory.js +++ b/src/growlFactory.js @@ -6,7 +6,8 @@ angular.module("angular-growl").provider("growl", function() { _messagesKey = 'messages', _messageTextKey = 'text', _messageSeverityKey = 'severity', - _onlyUniqueMessages = true; + _onlyUniqueMessages = true, + _callback = null; /** * set a global timeout (time to live) after which messages will be automatically closed @@ -57,6 +58,16 @@ angular.module("angular-growl").provider("growl", function() { this.onlyUniqueMessages = function(onlyUniqueMessages) { _onlyUniqueMessages = onlyUniqueMessages; }; + + /** + * defines a callback that would be called with the message object as parameter + * this callback can be use to process the message in the angular app, e.g. write the message to a status bar + * + * @param {function} callback default: null + */ + this.registerCallback = function (callback) { + _callback = callback; + }; /** * $http interceptor that can be added to array of $http interceptors during config phase of application @@ -112,6 +123,9 @@ angular.module("angular-growl").provider("growl", function() { }; broadcastMessage(message); + if (_callback) { + _callback(message); + } } /**