javascript - How to get headers details in angularJs application to show username in page header -


i have angular web application running on node.

on page header need show logged in user id/name. know user id, name available in headers information how can access them in angular , show them in header.html?

this information in angular docs:

returns promise object standard method , 2 http specific methods: success , error. method takes 2 arguments success , error callback called response object. success , error methods take single argument - function called when request succeeds or fails respectively. arguments passed these functions destructured representation of response object passed method. response object has these properties:

data – {string|object} – response body transformed transform functions.

status – {number} – http status code of response.

headers – {function([headername])} – header getter function.

config – {object} – configuration object used generate request.

statustext – {string} – http status text of response.

so, if make request, , userid supplied in response headers, can access this:

$http.get('someurl')     .success(function(data, status, headers) {         $scope.userid = headers('userid');     }); 

you may have inspect response headers see header value need access in order user id.

then add binding html:

{{userid}} 

here example showing how access $http response headers , display them in view:

  $scope.headers;   $scope.headerdate;   $http.get('test.json')   .success(function(data, status, headers) {     $scope.headers = headers();     $scope.headerdate = headers("date");   }); 

you can display response headers request putting {{headers}} or date header {{headerdate}}.

plunker


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -