简体   繁体   English

angularJs-看不到烤面包机错误

[英]angularJs - Can not see toastr error displayed

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. 我花了几个小时解决这个问题,但我无法解决:(我知道大约一个星期前我已经测试了该功能,并且看到了2条Toastr错误消息(不过,我不希望有两个错误消息)。我不确定到底发生了什么变化,但是现在我什至无法显示一个:(我完全看不到烤面包机消息。

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 我在控制台中看到[ItImagesSearchController]图片搜索控制器的初始化正在触发... / SiriuswareControl / api / itDraftHeaders / 1019无法加载资源:服务器响应状态为400(错误请求)2angular.js:14525 [ serverError]处理错误的请求

I also trace my code in the controller and I can see the line with toastr being executed. 我还在控制器中跟踪了我的代码,并且可以看到执行了toastr的那一行。 However, I see no toastr :( What can possibly be wrong? 但是,我看不到烤面包机:(可能有什么问题吗?

I believe I figured this out, but I am sort of back to square 1. I wanted to prevent duplicate toastr messages from being displayed, thus I have preventDuplicates: true in the server error toastr config. 我相信我已经解决了,但是我有点回到第1步了。我想防止显示重复的Toastr消息,因此我在服务器错误Toastr配置中具有了preventDuplicates:true。 However, it somehow made none of the messages to be displayed. 但是,它以某种方式使任何消息都无法显示。 When I slightly changed message in my controller, I saw both toastr messages now. 当我在控制器中稍稍更改了消息时,我现在看到了两个烤面包机消息。 How can I make only one of them to show? 如何只显示其中之一?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM