【发布时间】:2014-05-06 05:03:03
【问题描述】:
我很享受 Angular 依赖注入带来的鸡和蛋问题,我通过注入 $http 覆盖了 $exceptionHandler,但我也有一个自定义拦截器。
Uncaught Error: [$injector:unpr] Unknown provider: $httpProvider <- $http <- $exceptionHandler <- $rootScope
我正在尝试这样使用它:
Module.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('special-http');
}]);
我将拦截器包裹在工厂中:
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
}
【问题讨论】:
-
请添加jsfiddle或完整代码示例。
-
我的魔法水晶球告诉我,你忘记在任何你想使用的地方注入 $http
-
@AlexChoroshin 它是一个庞大的应用程序,所以不是真的,它以前以默认和预期方式工作
标签: angularjs