我正在尝试覆盖http标头中POST请求的标头默认值。即使我在函数参数中提供$ 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
答案 0 :(得分:11)
$ 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) {
});