Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS-$httpProvider,注册拦截器时出现未知提供程序错误_Javascript_Angularjs_Http_Token_Interceptor - Fatal编程技术网

Javascript AngularJS-$httpProvider,注册拦截器时出现未知提供程序错误

Javascript AngularJS-$httpProvider,注册拦截器时出现未知提供程序错误,javascript,angularjs,http,token,interceptor,Javascript,Angularjs,Http,Token,Interceptor,我正在尝试使用一个HTTP拦截器,它在服务器的每个请求之前添加一个令牌作为HTTP头 app.factory('httpRequestInterceptor', ['$rootScope', function($rootScope) { return { request: function($config) { if( $rootScope.token) {

我正在尝试使用一个HTTP拦截器,它在服务器的每个请求之前添加一个令牌作为HTTP头

app.factory('httpRequestInterceptor',
    ['$rootScope', function($rootScope)
    {
        return {
            request: function($config) {
                if( $rootScope.token)
                {
                    $config.headers['auth-token'] = $rootScope.token;
                }
                return $config;
            }
        };
    }]);
上面是我的拦截器,看起来不错。然后,在配置状态期间,我将这个拦截器推送到http提供程序,如下所示

app.config(function ($routeProvider, $httpProvider) {
    $routeProvider
        .when(...)
        .otherwise({
            redirectTo: '/'
        });
    $httpProvider.interceptors.push('httpRequestInterceptor');
});
现在,当查看我的浏览器控制台日志时,我得到一个错误,上面写着:
“未知提供程序:httpRequestInterceptorProvider对不起,这是一个愚蠢的错误,我忘了在索引中包含工厂。html://

对不起,这是一个愚蠢的错误,我忘了在索引中包含工厂。html://

defaultErrorMessageResolver
似乎是其中的一部分。您是否将
jcs autoValidate
模块作为依赖项包括在内?@Phil是的,我已将jcs autoValidate作为模块依赖项包括在内,自动验证工作正常。我刚刚更新了代码片段以显示整个app.js。我希望这能对您有所帮助,并感谢您的帮助。
defaultErrorMessageResolver
似乎是其中的一部分。您是否将
jcs autoValidate
模块作为依赖项包括在内?@Phil是的,我已将jcs autoValidate作为模块依赖项包括在内,自动验证工作正常。我刚刚更新了代码片段以显示整个app.js。我希望这会对你有所帮助,并感谢你的帮助。