Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing all toastr notifications
Message
 
 
À
Tous
Information générale
Forum:
Javascript
Catégorie:
Autre
Titre:
Removing all toastr notifications
Divers
Thread ID:
01637522
Message ID:
01637522
Vues:
45
Hi everybody,

We have the following directive (I'm showing relevant part of the code):
 var errorToastConfig = {closeButton:true,timeOut:0,tapToDismiss:true};

                $scope.$on('sm:badRequest', function (event, data) {

                    angular.forEach(data, function (value, key) {
                        if (value.message == '') value.message = 'The ' + value.property + ' value is invalid.'
                    });

                    $scope.errors = data;
                    //$scope.alertMessage = resourceFactory.getResource('Messages', 'errorOnForm');
                    //$scope.alertType = 'error';
                    $timeout(function () {
                        spinnerService.stopSpinner();
                    }, 0);
                    toastr.clear();
                    var errorMsg = ($scope.errors[0] && $scope.errors[0].message?$scope.errors[0].message:resourceFactory.getResource('Messages', 'errorOnForm'));

                    toastr.error(errorMsg, errorToastConfig);
                    $scope.disableAction = false;
                });
                
                });
The problem is that the on:badRequest fires twice for some reason (there is a loop for listeners in angularjs code and apparently there are several listeners) and as a result I see 3 toastr notifications (one is from my controller's code where the error is handled) and twice from this directive. Using toastr.clear() has no effect.

Do you see how to prevent that extra code from happening if the error is already handled in the code itself or at least remove other toastr from the screen?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform