$location from $exceptionHandler - dependency conflict

前端 未结 1 527
难免孤独
难免孤独 2021-02-03 23:53

I\'m trying to implement a very standard task: when an exception occurs, redirect to my /error page.

In a simplified form the code looks like this:

1条回答
  •  别那么骄傲
    2021-02-04 00:42

    To get around this you need to call the $injector manually to resolve the dependency at runtime:

    app.factory('$exceptionHandler', ['$injector', function($injector) {
    
        var $location;
    
        return function(exception, cause) {
            $location = $location || $injector.get('$location');
            $location.path("/error");
        };
    }]);
    

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