Problem with chicken and egg with dependency injection in angular, $ exceptionHandler and $ http

I like the problem with chicken and egg with dependency injection in angular, I override $ exceptionHandler by entering $ http, but I also have a custom interceptor.

Uncaught Error: [$injector:unpr] Unknown provider: $httpProvider <- $http <- $exceptionHandler <- $rootScope 

I am trying to use it like this:

 Module.config(['$httpProvider', function($httpProvider) { $httpProvider.interceptors.push('special-http'); }]); 

I wrapped my interceptor in a factory:

 Module.factory('special-http', ['$templateCache', function($templateCache) { "use strict"; return { 'request': function(config) { if ($templateCache.get(config.url)){ return config; } //some logic return config; } } }]); 

exceptionHandler.js

 Module.factory('$exceptionHandler', [' $http', function ($http) { "use strict"; //code } 
0
angularjs
Mar 27 '14 at 9:56
source share
1 answer

Here is a working example of creating interceptors .

Example:

 app.config(['$httpProvider', function($httpProvider) { $httpProvider.interceptors.push(function($q) { return { 'request': function(config) { // same as above }, 'response': function(response) { // same as above } }; }); }]); 

Real-time example: http://jsfiddle.net/choroshin/mxk92/

+1
Mar 27 '14 at 10:35
source



All Articles