3

Consider the following interceptor template for angular 1

    (function () {
        'use strict';

        angular
            .module('myApp')
            .factory('apiError', apiError);

        apiError.$inject = [
            '$q',
            '$injector',
            '$http'];

        function apiError($q,
                          $injector,
                          $http) {

        }
    })();

Injecting $q and $injector will not encounter any problem, but injecting $http will cause circular dependency error.

Error: $injector:cdep
Circular Dependency

The fix I made is simply setting $http using $injector inline

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

But I have two questions

  1. Why is there circular dependency?
  2. How did $injector solved the circular dependency
user445670
  • 179
  • 8
  • start here http://stackoverflow.com/questions/19344214/problems-with-circular-dependency-and-oop-in-angularjs – charlietfl Sep 29 '16 at 19:03

0 Answers0