Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add callback parameter to process message in calling angular app #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/growlFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -112,6 +123,9 @@ angular.module("angular-growl").provider("growl", function() {
};

broadcastMessage(message);
if (_callback) {
_callback(message);
}
}

/**
Expand Down