本文介绍了AngularJS 1.7.9:如何调试“可能未处理的拒绝:{}"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道类似的问题,例如 Angularjs 1.7.9 - 可能未经处理的拒绝和其中提到的重复.

I am aware of siiar questions, such as Angularjs 1.7.9 - Possibly unhandled rejection and those mentioned in it as duplicates.

但是,我的代码没有使用承诺(我知道;当然没有 $promise$http).

However, my code does not use promises (that I am aware of; certainly no $promise or $http).

我只是在为朋友制作一个简单的 ui-router 演示.它只有两个视图,每个视图都有一个可以切换到另一个视图的按钮.它在 AngulrJs 1.5 中运行良好,但在 1.7 中因上述错误而中断.

I am just knocking up a simple ui-router demo for a friend. It is just two views, each with a button that toggles to the other view. It works just fine with AngulrJs 1.5, and breaks with the above error in 1.7.

虽然很简单,但发布的代码有点太多了.万一,与其在我的代码中发现错误,我更希望得到一个规范的答案,以帮助将来阅读此问题的其他人:如何解决此错误消息?

A simple as it is, it's a bit too much code to post. In case, rather than finding the error in my code, I woudl like a canonical answer to help others who read this question in future : how to go about denugging this error message?

错误:转换失败(由可能未处理的拒绝:{}"引起)

at r [as $get] (http://localhost/common/js/third_party/ui-router_zero_pint_2_point_11/angular-ui-router.min.js:7:11365)
at Object.invoke (http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:45:62)
at http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:46:365
at d (http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:43:495)
at e (http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:44:235)
at Object.invoke (http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:44:320)
at http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:47:18
at r (http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:8:76)
at fb (http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:46:499)
at c (http://localhost/common/js/third_party/angular-1_point_7_point_9/angular.min.js:22:57)

推荐答案

如果您使用 angular.js 而不是 angular.min.jsangular-ui-router.js 而不是 angular-ui-router.min.js.Angular-UI-Router 在它的转换模块中使用了 promises.看起来您升级了 AngularJS 的版本,而没有升级 Angular-UI-Router 的版本.将您的路由器从 V0.2.11 升级到 V0.4.3.看起来您的问题是由草率的 Angular-UI-Router 代码引起的.如果他们没有通过 V0.4.3 解决问题,您可以修补库或处理消息.

You will get a more informative stack trace if you use angular.js instead of angular.min.js and angular-ui-router.js instead of angular-ui-router.min.js. Angular-UI-Router uses promises in its transition module. It looks like you upgraded your version of AngularJS without upgrading the version of Angular-UI-Router. Upgrade your router from V0.2.11 to V0.4.3. It looks like your problem is caused by sloppy Angular-UI-Router code. If they didn't fix the issue by V0.4.3, you can either patch the library or live with the messages.

堆栈跟踪将显示错误来源的文件和行号.检查代码并解决问题.如果错误源于第三方库,请尝试升级到最新版本或联系第三方库供应商.

The stack trace will show the file and the line number from which the error originates. Examine the code and fix the problem. If the error orginates in a third- party library, try upgrading to the latest version or contacting the third-party library vendor.

作为最后的手段,禁用可能未处理的拒绝" 消息:

As a last resort, disable the "possibly unhandled rejection" messages:

app.config(functon ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
});

不推荐这样做,因为它会让其他问题无声无息地失败.

This is not recommended as it allows other problems to silently fail.

如果不关心特定的承诺失败,请添加一个 .catch 处理程序:

If one doesn't care about a specific promise failing, add a .catch handler:

$http(config).then(function(response) {
    //...
}).catch(function(response) {
   //I don't care about errors
   if (debug) console.log(response);
   //Re-throw error response
   throw response;
})

升级 AngularJS

升级 AngularJS 时,最好同时升级所有 AngularJS 模块.即从[email protected]迁移到[email protected],同时升级到[email protected][email protected][email protected] 等.我在尝试混合和匹配 AngularJS 模块的版本时遇到了令人不快的问题.

Upgrading AngularJS

When upgrading AngularJS, it is best to upgrade all of the AngularJS modules at the same time. That is when migrating from [email protected] to [email protected], at the same time upgrade to [email protected], [email protected], [email protected], etc. I have seen unpleasant problems when trying to mix and match versions of AngularJS modules.

迁移时,我建议一次升级一个次要版本.例如,先从 V1.4 升级到 V1.5,修复损坏的地方,然后再升级到 V1.6.

When migrating, I recommend upgrading one minor version at a time. For example, upgrade from V1.4 to V1.5 first, fix what breaks, then upgrade to V1.6.

当前版本为1.7.9污染根除(2019-11-19).我建议使用最新版本,因为 AngularJS 团队已经承诺只修复 V1.2.x 和最新版本中的安全漏洞.如需更多信息,请参阅

The current version is 1.7.9 pollution-eradication (2019-11-19). I recommend using the latest version as the AngularJS team has committed to fixing security bugs only in both V1.2.x and the latest version.For more information, see

AngularJS 的 UI-Router 有两个主要版本

UI-Router for AngularJS has two major versions

版本 0.4.3 UI-Router-遗产

版本 1.0.25 AngularJS 的 UI-Router

我建议先升级到最新版本的 UI-Router-Legacy,然后再迁移到适用于 AngularJS 的最新版本的 UI-Router.两者之间发生了重大的突破性变化,最好循序渐进地处理.

I recommend upgrading to the latest version of UI-Router-Legacy before migrating to the latest version of UI-Router for AngularJS. There have been major breaking changes between the two and it is best to deal with it incrementally.

有关更多信息,请参阅

这篇关于AngularJS 1.7.9:如何调试“可能未处理的拒绝:{}"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:51