JanStevens / angular-growl-2

growl-like notifications for angularJS projects
MIT License
285 stars 97 forks source link

reset all inline growls when changing state #112

Closed hugsbrugs closed 8 years ago

hugsbrugs commented 8 years ago

Hi I have growls with disabled countdown (ttl:-1) and thus when changing route, I would like to reset those notifications (only the inline ones), so that when I come back, I don't see them unless they are fired again !

For the router part, I know where to start :

$rootScope.$on('$stateChangeStart', function(event, state, params)
{
       // Reset inline growls
});

But for growl reset I'm completely lost : what object should I look at ? is there any method or hack for achieving this ?

flippinjoe commented 8 years ago

I believe what you want here is growlMessages.deleteAllMessages()

flaviocysne commented 8 years ago

I'm using ng-route instead of ui-route, but It's a minor code change away.

As ng-route there's no "state" definition I had to add a property called "group" to know when I'm changing business scopes.

.run(['$rootScope', 'growlMessages', function($rootScope, growlMessages){
        $rootScope.$on('$routeChangeSuccess', function(event, current, previous, rejection){
            if (current && previous && current.group !== previous.group) {
                growlMessages.destroyAllMessages();
            }
        });
    }]);
hugsbrugs commented 8 years ago

Thanks @flaviocysne ,

I'll give growlMessages.destroyAllMessages(); a try because that was the function called I missed !