0
I have the file interface-Factory.js which is my factory
app.factory('interfaceAPI', function ($http) {
var _getInterface = function () {
return $http.get("/api/interfaceapi/getall");
};
var _postInterface = function (objeto) {
return $http.post("/api/interfaceapi/post", objeto);
};
var _deleteInterface = function (Id) {
return $http.delete("/api/interfaceapi/delete/" + Id);
};
return {
getInterface: _getInterface,
postInterface: _postInterface,
deleteInterface: _deleteInterface
};
});
the token is already being generated and being saved from localStorage, I would like to know how to pass the token in the header of each request.
var myToken = JSON.parse(localStorage.getItem('token'));
$http.defaults.headers.common['Authorization'] = myToken.token_type + myToken.access_token;

Desta forma?
– Jefferson Souza
@Jeffersonsouza edited the answer according to the code you reported. I hope it solves your problem!
– Hamurabi Araujo
this way did not work.
– Jefferson Souza
Error appeared in the console or simply did not set the header?
– Hamurabi Araujo
did not set the header
– Jefferson Souza
Return $http.get("/api/interfaceapi/getall"), config; then I can get into the page I want, but I know it’s not the right one. config is my variable where it receives token type and token
– Jefferson Souza
gave a console.log to see if the values are being picked up, and are
– Jefferson Souza
For the sake of conscience, do a test using:
$http.defaults.headers.common.Authorization = ...
– Hamurabi Araujo
together with the code you sent?
– Jefferson Souza
Yes. In this case, replace the third line of the example I quoted
$http.defaults.headers.common['Authorization'] = myToken.token_type + myToken.access_token;
for$http.defaults.headers.common.Authorization = myToken.token_type + myToken.access_token;
– Hamurabi Araujo