E
E
Eka22016-07-19 02:45:02
Angular
Eka2, 2016-07-19 02:45:02

Why does the $injector:cdep Circular Dependency error occur?

There is a service for issuing messages:

angular.module('Notes',['ui.bootstrap']);
         
angular
   .module('Notes')
   .service('Srv', Srv);
   Srv.$inject = ['$uibModal'];
function Srv ($uibModal) {
  this.say = function(msg) {
  ...
}
return this;
}

When called from any controller, everything works:
angular
   .module('app')
   .controller('PCC' , PCC);
PCC.$inject = ['Srv'];
function PCC(Srv) {		
      Srv.say('message');
}

When trying to inject a service into an Interceptor:
angular
.module('app', ['ngResource', 'Notes'])

Interceptor = angular.module('app')
 .factory('Interceptor',['Srv',function(Srv)
 { 	var Interceptor = {
    'response': function(response) {
      	Srv.say('message');
    }
  }
  return Interceptor;
}]);

angular
.module('app')
.config(['$httpProvider',
function($httpProvider) {
    $httpProvider.interceptors.push('Interceptor');
}]);

$injector:cdep Circular Dependency error occurs.
Tell me, please, what is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question