Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing all toastr notifications
Message
 
 
To
All
General information
Forum:
Javascript
Category:
Other
Title:
Removing all toastr notifications
Miscellaneous
Thread ID:
01637522
Message ID:
01637522
Views:
46
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
Next
Reply
Map
View

Click here to load this message in the networking platform