Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while accessing the $httpProvider.defaults.headers configuration object in angularJS

Tags:

angularjs

I am trying to overwrite header defaults for POST requests in http header. Even i am providing $httpProvider in the function argument, but still it is throwing error.

Code is -

 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';

 });

The error is -

Error: [$injector:unpr] Unknown provider: $httpProviderProvider <- $httpProvider <- sharedProperties

like image 402
Neha Gupta Avatar asked Dec 11 '22 05:12

Neha Gupta


1 Answers

$httpProvider is accessible only in config... you should change you code like:

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) {

});
like image 95
Bogdan Savluk Avatar answered May 24 '23 22:05

Bogdan Savluk