AngularJS possible unhandled rejection when using ui-router

余生长醉 提交于 2019-12-30 04:28:06

问题


After I have changed from ngRoute to angular-ui-router the console shows always 4 errors stating: Possibly unhandled rejection: {}

I did not noticed any "problem" in the behavior of the application I am building, but I would like to get rid of it.

Any idea what does it mean and how to solve it?

Here an screenshot:


回答1:


This issue is found in 1.5.9 and 1.6.0-rc-0. More details at https://github.com/angular-ui/ui-router/issues/2889

Patch solution is to manually disable unhandled rejections.

app.config(['$qProvider', function ($qProvider) {
    $qProvider.errorOnUnhandledRejections(false);
}]);



回答2:


If you look at the logic for uiCanExit in angular-ui-router file(I'm using v1.0.16), it checks only for resolved promise but not for a rejected promise. It is something like:

promise.then(function (val) { 
    return val !== false ? next_transition : current_transition
});

Just return a resolved promise with false value to cancel transition. e.g.,

defer.resolve(false)



回答3:


Resolve the promise with false if you are trying to abort a transition.




回答4:


I used the next solution

    $http.get('/api/get').then(function(result) {
       // ... stuff here
    }).catch(angular.noop);

it's equals to

$http.get('/api/get').then(function(result) {
  // ... stuff here
}).catch(function(){});


来源:https://stackoverflow.com/questions/39931983/angularjs-possible-unhandled-rejection-when-using-ui-router

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!