Error handling in Angular with inject

0

I recently asked how to get errors js in Angular 1.6 but now I'm having a problem trying to inject $http to factory . I get the following error:

Circular dependency found: $rootScope <- $http <- $exceptionHandler <- $rootScope <- $route

And this was what I was doing so far:

var app = angular.module("app", []);
app
  .controller("ctrl", function($scope) {
    // controller
  })
  .factory('$exceptionHandler', ['$log', '$http', function($log, $http) {
    return function myExceptionHandler(exception, cause) {
      $log.warn(exception, cause);
      // muestro sólo esto y ya tira error
      console.log($http);
    }
  }]);
    
asked by Kleith 13.04.2018 в 17:27
source

1 answer

1

instead of injecting $http directly into the interceptor, I try to inject from $injector and use it directly to get $http .

var app = angular.module("app", []);
app.factory('$exceptionHandler', ['$log', '$injector', function($log, $injector) {
    return function myExceptionHandler(exception, cause) {
        var $http = $injector.get('$http');
        $log.warn(exception, cause);
        // muestro sólo esto y ya tira error
        console.log($http);
    }
}]);
    
answered by 18.04.2018 / 16:03
source