how to add a request Headers with $ http de angularjs?

0

I'm doing a service consumption and I want to add a header to the get method in the following way.

    var header={headers: {'idUser': Constants.appConfig.userParam} };
    return {
        obtenerInformacionUsuario: () => 
           $http.get(${BASE_URL2}/obtenerInformacionUsuario, header)
    }

In Constants.appConfig.userParam a string is saved, the service returns data and everything but the problem is that I do not add the idUser to the Request Headers.

    
asked by Alberto Rojas 04.11.2017 в 01:26
source

1 answer

0

Try using the $http method directly specifying the headers:

$http({
    method: 'GET',
    url: '${BASE_URL2}/obtenerInformacionUsuario',
    data: 'data=1',
    headers: {
         "idUser": Constants.appConfig.userParam
    }
}).then(function(response) {
    //...
});
    
answered by 04.11.2017 в 01:55