Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Removing all toastr notifications
Message
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01637522
Message ID:
01637577
Vues:
32
I think I figured out the reason why it fires twice but I haven't yet figured out how to solve it. All our edit forms have server-error directive, but our main _layout.cshtml apparently also have that directive in the middle of the page for the change password form. So, the directive is being hit twice.

One of the solutions is probably to remove that directive from all our forms since the main layout form already have it. But I'm wondering if that would still work correctly in case the actual form has a problem with some fields.

>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform