question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Circular dependency in interceptors

See original GitHub issue

I am having this exact same issue: https://github.com/alexcrack/angular-ui-notification/issues/29

I tried the code and I did not have any success.

angular.module('ui', [])
    .config(function($httpProvider) {
        $httpProvider.interceptors.push('baseHttpInterceptor');
    })
   .factory('baseHttpInterceptor', function ($injector) {

       var Notification = $injector.get('Notification');

       return {
           'responseError': function() {
               Notification.error('Oops');
           }
       };
    });

Circular dependency error:

Circular dependency found: 
$compile <- Notification <- baseHttpInterceptor <- $http <- $templateRequest <- $compile

Any ideas?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
MarkPerryBVcommented, Jul 1, 2015

I have just had the same problem. The issue arises that inside of “Notification” there is a dependency on $http and $templateCache.

What I have done and which seems to work is to delay the construction of Notification until it’s needed in the interceptor.

.factory('baseHttpInterceptor', function ($injector) {
var notification = null;
        var getNotification = function() {
            if (!notification) {
                notification = $injector.get('Notification');
            }
            return notification;
        };
       return {
           'responseError': function() {
               getNotification().error('Oops');
           }
       };
    });
0reactions
alexcrackcommented, Aug 14, 2015

I think it wasn’t the ui-notification’s error. It’s because angular’s injector cannot correctly inject some services to interceptors. I’ve seen this trouble using another modules. So, I’m closing issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Circular dependency when inject TranslateService to ...
This causes a cyclic dependency since your interceptor needs the TranslateService . You can workaround this by injecting the Injector in ...
Read more >
Cyclic dependency error with HttpInterceptor #18224 - GitHub
@perusopersonale that stack overflow error means that your circular dependency has been resolved at build time but is still very much present at ......
Read more >
Circular Dependencies in Angular and the Injector Service
A real-world circular dependency. Enter HTTP interceptors. Interceptors are Angular's very handy tool for handling cross-app concerns when it ...
Read more >
Package de.hybris.platform.b2ctelcoservices.interceptors
Validation Interceptor making sure that no circular dependency can be formed within a give composite Item. BpoCircularDependencyValidationInterceptor.
Read more >
AngularJS: Injecting service into a HTTP interceptor (Circular ...
JavaScript : AngularJS: Injecting service into a HTTP interceptor ( Circular dependency ) [ Gift : Animated Search Engine ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found