在我的Angularjs应用程序中,我有一个工厂,需要对用户进行身份验证。我正在使用httpProvider
来设置默认值。但是我收到错误,说明$httpProvider
未定义。无法在angularjs工厂内设置http默认值
'use strict';
angular.module('myApp')
.factory('authService', function ($q, $http, $rootScope, $window) {
return {
authenticateUser: function() {
........
........
$httpProvider.defaults.headers.common['Accept'] = 'application/json, text/javascript';
$httpProvider.defaults.headers.common['Content-Type'] = 'application/json; charset=utf-8';
我然后在工厂的依赖
'use strict';
angular.module('myApp')
.factory('authService', function ($q, $http, $rootScope, $window, httpProvider) {
return {
authenticateUser: function() {
........
........
$httpProvider.defaults.headers.common['Accept'] = 'application/json, text/javascript';
$httpProvider.defaults.headers.common['Content-Type'] = 'application/json; charset=utf-8';
这一次,我收到Unknown provider: $httpProviderProvider <- $httpProvider <- authService
请让我知道我错了加入$httpProvider
尝试。
我在你的代码片段中看到了这个:'$ httpProvider.interceptors.push('authInterceptorService');'如果我有很多服务需要使用'拦截器'? – zilcuanu
有一个问题。我在哪里配置定义?我将'config'设置为'undefined' – zilcuanu
@Pradeep,你正在问的是哪个'config'? 'angular.module.config()'或名称为“config”的参数? –