AngularJS possible unhandled rejection when using ui-router

前端 未结 4 534
深忆病人
深忆病人 2020-12-16 02:25

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

I did not noticed

相关标签:
4条回答
  • 2020-12-16 02:44

    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)
    
    0 讨论(0)
  • 2020-12-16 02:53

    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);
    }]);
    
    0 讨论(0)
  • 2020-12-16 02:53

    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(){});
    
    0 讨论(0)
  • 2020-12-16 03:04

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

    0 讨论(0)
提交回复
热议问题