Working for me:
$http.defaults.headers.common['Authorization'] = 'Bearer ' + token;
Вопрос
I'm using Angular 1.2 with Restangular. I need set header access_token after user is authorized and since then this header needs to be send with every request. I tried to do it this way:
angular.module('controllers', [])
.controller('Login', function($scope, Restangular) {
$scope.signin = {};
$scope.submitSignin = function() {
var signin = Restangular.all('oauth/access_token');
oauthPost = {
grant_type: 'password',
client_id: 'some_id',
client_secret : 'some_secret_code',
username: $scope.signin.email,
password: $scope.signin.password
};
signin.post(oauthPost).then(function(data) {
Restangular.setDefaultHeaders({accept: 'application/json',access_token: "somelongstring"});
}, function() {
console.log("There was an error.");
});
};
})
Решение
Working for me:
$http.defaults.headers.common['Authorization'] = 'Bearer ' + token;