我正在尝试覆盖 http header 中 POST 请求的 header 默认值。即使我在函数参数中提供 $httpProvider ,但它仍然抛出错误。
代码是——
angular.module('myApp.services', ['ngCookies'])
.service('sharedProperties', function ($cookieStore, $http, $httpProvider) {
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www- form-urlencoded;charset=utf-8';
});
错误是——
错误:[$injector:unpr] 未知提供者:$httpProviderProvider <- $httpProvider <- sharedProperties
最佳答案
$httpProvider 只能在配置中访问...你应该改变你的代码,如:
angular.module('myApp.services', ['ngCookies'])
.config(function($httpProvider){
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
})
.service('sharedProperties', function ($cookieStore, $http) {
});
关于angularjs - 在 angularJS 中访问 $httpProvider.defaults.headers 配置对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24196145/