1

i have a REST API (developed using Spring Boot), i am using AngularJS 1.5 in the frontend, the login service sends besides the data a header, how can i read both data and header in angularjs side

var LocalBusinessUserResource = $resource(apiService + '/localbusinessusers/login');
var deferred = $q.defer();
            LocalBusinessUserResource.get(credantials, function (result) {
                console.log('result: ' + JSON.stringify(result));
                deferred.resolve(result);
            }, function () {
                console.error('check your server connection');
            });
            return deferred.promise;
jemlifathi
  • 1,482
  • 5
  • 22
  • 32

1 Answers1

0

From the $http docs:

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.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.

You have access to the response headers on the same object that you get the response data from.

  • i'm not using $http and for all my calls i have used $resource – jemlifathi Apr 10 '16 at 14:20
  • Ah, my mistake. In that case, you should be able to access the response headers by adding a second parameter to the callback like this: `LocalBusinessUserResource.get(credantials, function (result, responseHeaders) {...`; – unscsprt Apr 10 '16 at 14:33