I spent several hours on this problem and I can not figure this out :( I know that I tested that functionality about a week or so ago and I saw 2 toastr error messages displayed (I didn't want two of them, though). I am not sure what exactly changed but now I can not get even a single one displayed :( I see no toastr message at all.
My code is:
app.directive('serverError', ['resourceFactory', 'spinnerService', 'toastr', '$log',
function (resourceFactory, spinnerService, toastr, $log) {
return {
restrict: 'A',
controller: ['$scope', '$timeout', function ($scope, $timeout) {
log = $log.getInstance("serverError");
var errorToastConfig = {
closeButton: true,
timeOut: 0,
extendedTimeOut: 0,
tapToDismiss: false,
preventDuplicates: true
};
var title = resourceFactory.getResource("Messages", "applicationError");
$scope.$on('sm:badRequest', function (event, data) {
if (!$scope.errorHandled && !$scope.showForm) {
log.debug("Handling bad request");
let errorMsg = "";
angular.forEach(data, function (value, key) {
if (value.message == '') value.message = 'The ' + value.property + ' value is invalid.'
errorMsg = errorMsg + value.message + " ";
});
errorMsg = errorMsg.trim();
$scope.errors = data;
toastr.clear();
if (errorMsg=="")
errorMsg = resourceFactory.getResource('Messages', 'errorOnForm');
title = resourceFactory.getResource("Messages", "badRequest");
toastr.error(errorMsg, title, errorToastConfig);
}
$scope.disableAction = false;
});
And then also in the controller:
function (error) {
spinnerService.stopSpinner('loaditemtree');
$scope.stopExecution = true;
if (error.hasOwnProperty("data")) {
toastr.clear();
let errorMsg = error.data[0].message;
toastr.error(errorMsg);
}
});
I see in the console [ItImagesSearchController] Init of the Images Search Controller is firing... /SiriuswareControl/api/itDraftHeaders/1019 Failed to load resource: the server responded with a status of 400 (Bad Request) 2angular.js:14525 [serverError] Handling bad request
I also trace my code in the controller and I can see the line with toastr being executed. However, I see no toastr :( What can possibly be wrong?