I am trying to inject custom header to every API request. When I am providing some hard coded text it works.
Working code
myApp.config(['$httpProvider', function ($httpProvider) { var requestInterceptor = ['$q', '$rootScope', function ($q, $rootScope) { var interceptorInstance = { request: function (config) { config.headers['X-MyApp-CustomHeader'] = "foobar"; return config || $q.when(config); } }; return interceptorInstance; }]; $httpProvider.interceptors.push(requestInterceptor); }]); Not working code
myApp.config(['$httpProvider', function ($httpProvider) { var requestInterceptor = ['$q', '$rootScope', '$route', function ($q, $rootScope, $route ) { var interceptorInstance = { request: function (config) { config.headers['X-MyApp-CustomHeader'] = $route.current.params.CustomParameter; return config || $q.when(config); } }; return interceptorInstance; }]; $httpProvider.interceptors.push(requestInterceptor); }]); Error, When trying to inject $route
Uncaught Error: [$injector:cdep] Circular dependency found: $route <- $http http://errors.angularjs.org/1.2.3/$injector/cdep?p0=%24route%20%3C-%20%24http