Grigoris Loukidis
Grigoris Loukidis

Reputation: 403

When showing a new growl in angularjs clear the old ones from view

I am working on growl.info() on angularjs and I have a question. How can I check if a growl exists in view (screen), when trying to add a new one? If a new one tries to be shown the previous one must be erased from screen. The code in controller is this:

$scope.showInfo= function () {

        var info = "test";

        growl.info(message.replace("{0}", info), {
            ttl: 50000
        });
    };

but note that ttl is important too. If no new growl tries to be shown, the first must live for a long period. Thank you in advance!

Upvotes: 0

Views: 370

Answers (1)

Grigoris Loukidis
Grigoris Loukidis

Reputation: 403

Firslty we add a public variable:

$scope.growlMessge = null;

and then we check if it has already a value (just to destroy it), before giving the new one

 $scope.showInfo= function () {

   if ($scope.growlMessage != null) {
            $scope.growlMessage.destroy();
     }

    var info = "test";

    $scope.growlMessage = growl.info(message.replace("{0}", info), {
        ttl: 50000
    });
};

Upvotes: 1

Related Questions