angular-growl-2 icon indicating copy to clipboard operation
angular-growl-2 copied to clipboard

Removing messsage from Controller

Open eduardoinnorway opened this issue 9 years ago • 4 comments

There are many scenarios where you want to destroy the message/messages from the Controller for example on state change with ui-router, the message is still there. Or destroy the error message ones the form is valid again.

I think you should add to the docs that you can remove messages from the Controller like this for example:


var formErrorMessage = growl.error('You have an error in your form.'); //Instant show just example

var destroyErrorMessage = function() { formErrorMessage.destroy(); };

//Call destroyErrorMessage() after validation success, next state or where ever.

Note! above is just example to show and destroy, so this will open the error message instantly.

eduardoinnorway avatar Aug 14 '15 14:08 eduardoinnorway

I second this idea. It might be easier to also have growl.clearAll(), which clears all visible notifications. I would want to use this after a state change with ui-router.

ibnIrshad avatar Sep 05 '15 13:09 ibnIrshad

With the latest version (0.7.5), you can do it by using the growlMessages service like this:

.run(function ($rootScope, growlMessages) {
        $rootScope.$on('$stateChangeSuccess', () => {
            growlMessages.destroyAllMessages();
        });
    });

Note that on 0.7.3 there was an issue with the way destroyAllMessages looped over the messages internally, so that wouldn't work.

fabiosussetto avatar Sep 28 '15 12:09 fabiosussetto

The snippet posted by @fabiosussetto in https://github.com/JanStevens/angular-growl-2/issues/102#issuecomment-143724500 will break when uglifying. Here is a minification-safe version:

.run(['$rootScope', 'growlMessages', function ($rootScope, growlMessages) {
        $rootScope.$on('$stateChangeSuccess', function () {
            growlMessages.destroyAllMessages();
        });
    }]);

janpapenbrock avatar Dec 18 '15 11:12 janpapenbrock

@janpapenbrock you're right, I copied from one of our projects where we use ng-annotate to automatically deal with the problem.

fabiosussetto avatar Dec 18 '15 12:12 fabiosussetto