Answer the question
In order to leave comments, you need to log in
How to get data from AngularJS header?
Hello, such a situation, I turn to the server with data for authorization, through the resource, a token comes in the header, but I just don’t understand how to get it out, I’m not banned in Google, a couple of hours of searching did not bear fruit in general:
$http.post(urlForResource+'authorization/user', user).then(function(response){
console.log(response);
});
Answer the question
In order to leave comments, you need to log in
the data that you receive must operate on your own, i.e. where did you define the location of the token?
for example, I put the token in localStorage and can easily get it from there.
The response object has these properties :
data - {string|Object} - The response body transformed with the transform functions.
status - {number} - HTTP status code of the response.
config - {Object} - The configuration object that was used to generate the request.
statusText - {string} - HTTP status text of the response.
response.headers('token');
//или
response.headers()['token'];
It will return a specific
one. It will return the headers object and you will be able to see what you have received and already apply by property.
Here is an example from the documentation
plnkr.co/edit/KnhuUIb0IpqEoNPOXabz?p=preview
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question