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

Removing messsage from Controller #102

Open
eduardoinnorway opened this issue Aug 14, 2015 · 4 comments
Open

Removing messsage from Controller #102

eduardoinnorway opened this issue Aug 14, 2015 · 4 comments

Comments

@eduardoinnorway
Copy link

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.

@ibnIrshad
Copy link

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.

@fabiosussetto
Copy link

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.

@janpapenbrock
Copy link

The snippet posted by @fabiosussetto in #102 (comment) will break when uglifying. Here is a minification-safe version:

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

@fabiosussetto
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants