我试图覆盖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
最佳答案
$ 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) {
});