Reputation: 565
My API uses the Accept-Language header to get it's current language which returns the json translated. Never mind that.
How can i change the header with angularJS/Javasctipt. I tried this:
$http.defaults.headers.post["Accept-Language"] = "bs-Latn-BA";
but it doesn't seem to work, are there any other alternatives?
Upvotes: 1
Views: 4680
Reputation: 11541
The default headers sent for every single request live in the $httpProvider.defaults.headers.common
object.
You can change or augment these headers using the .config()
function for every request, like so:
angular.module('myApp', [])
.config(function($httpProvider) {
$httpProvider.defaults.headers
.common['Accept-Language'] = 'bs-Latn-BA';
});
We can also manipulate these defaults at run time using the defaults property of the $http
object. For instance, to add a property for dynamic headers, we can set the header property like so:
$http.defaults
.common['Accept-Language'] = "bs-Latn-BA";
Upvotes: 4
Reputation: 3476
AngularJS you can set common headers by using $httpProvider. Angularjs
Example:
var app = angular.module("app", []);
app.config(["$httpProvider", function($httpProvider) {
// set Accept-Language header on all requests to
$httpProvider.defaults.headers.common["Accept-Language"] = "bs-Latn-BA";
}]);
Upvotes: 2