AngularJS 1.7.9:如何调试“可能未处理的拒绝:{}”?

问题描述 投票:1回答:2

我知道一些类似的问题,例如Angularjs 1.7.9 - Possibly unhandled rejection和其中提到的重复项。

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

我只是为一个朋友制作了一个简单的ui-router演示。它只是两个视图,每个视图都有一个切换到另一个视图的按钮。它在AngulrJs 1.5中可以正常工作,并在1.7中因上述错误而中断。

非常简单,要发布的代码太多了。以防万一,而不是在我的代码中找到错误,我希望得到一个规范的答案,以帮助将来阅读此问题的其他人:如何着手否认此错误消息?

Error: transition failed (caused by "Possibly unhandled rejection: {}")  
    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)  
angularjs debugging error-handling angular-ui-router
2个回答
1
投票

调试ui-router的一种方法如下:

从控制台注入$state服务,键入以下内容:

var test = angular.element(document.body).injector().get('$state');

然后模拟并执行导致问题的过渡:

test.go('root.details') // use the state url here

之后,过渡的详细信息将打印在控制台中。在$$state对象中,您可以找到有关转换失败和失败原因的更多详细信息:enter image description here


1
投票

一个人很清楚,某些东西被拒绝了(一种承诺,一种资源或某种东西)。

如果您不使用任何承诺,则可能还有其他东西,可能是一种资源。

我按照您想要的相同方式创建了这个Codepen https://codepen.io/surya-iitg/pen/qBdRJpY,使用angularjs版本1.7.9和angular-ui-router版本0.3.2(少得多),我看到相同的错误,当templateUrl为无法访问或不存在。

$stateProvider
  .state('s1', {
    url: '/s1',
    templateUrl: 's1.html',
    controller: 'S1Controller'
  })
  .state('s2', {
    url: '/s2/:id',
    templateUrl: 's3.html', //This does not exists, it should be s2.html in my demo
    controller: 'S2Controller'
  });

当资源可以访问时,在我的演示中s2.html,一切正常。

如果我使用的是最新版本的angular-ui-router 1.0.7,则错误会有所不同,但是当然这也不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.