2

Trying to create a global error handler that should present an error modal on error by configuring the $httpProvider adding a interceptor. The modal produces a dependency on a service. Which I can't inject into a config block. I have tried lazy loading the service using $injector, but doesn't work. How would you solve it?

edit just found $exceptionHandler, trying it. No luck cirk dep :$modal <- errorModalService <- $exceptionHandler <- $rootScope

1
  • Please show as much relevant code as possible. Commented May 22, 2014 at 18:06

1 Answer 1

4

Yes, it is true that AngularJS DI subsystem can be tricky with circular dependencies. Not sure what you've tried and what didn't work but you can always get a required dependency from the $injector. Doing so from a $http interceptor is pretty easy:

  .factory('errInterceptor', function ($q, $injector) {
    return {
      responseError: function(response) {
          $injector.get('$modal').open({
            template: '<h4>$http error!</h4>',
          });
      }
    }
  })

Here is a working plunk: http://plnkr.co/edit/n172IrR9259qi4qG0H3I?p=preview

Sign up to request clarification or add additional context in comments.

1 Comment

looks promising, trying it now!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.