Why does angular $ http provide headersGetter instead of headers?

When used $http

, callbacks are called using the headers gate. This often leads to the following code:

$http.get('example.json').success(function(data, status, headersGetter, config) {
  var headers = headersGetter();
  // Do stuff
});

      

Why is headersGetter passed to the callback and not just headers as an object?

+3


source to share


1 answer


Why is headersGetter passed to the callback and not just headers as an object?

This is explained in the docs as follows:

A getter is a function that returns a view of the model. It is sometimes useful to use this for models that have a different internal representation than what the model exposes for presentation.

Specifically for headersGetter

, being a function, facilitates the following:



This allows you to either get the entire headers object passed in the config, or a specific header value by name (case insensitive).

Links

0


source







All Articles