angularjs - 为什么 Angular $http 提供 headersGetter 而不仅仅是 headers?

标签 angularjs angular-http

当使用 $http 时,回调函数是通过 headers getter 调用的。这通常会产生以下代码:

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

为什么将 headersGetter 传递给回调而不是仅将 header 作为对象传递?

最佳答案

Why is a headersGetter passed to the callback instead of just the headers as an object?

文档中对此进行了如下解释:

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

特定于 headersGetter,作为一个函数有助于实现以下目的:

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

引用文献

关于angularjs - 为什么 Angular $http 提供 headersGetter 而不仅仅是 headers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26661649/

相关文章:

angularjs - 如何从finally block 访问$http响应

angularjs - 使用 Angularjs 强制 "soft"更新字段

angularjs - 从 angularjs 中的下拉菜单调用 href

javascript - Promise.all 每次处理一组 6 个 promise

javascript - 使用 $http 获取 JSON 数据

javascript - Angular 服务不过滤数据

javascript - Angular 2 HTTP json 请求在尝试解析结果时给我一个奇怪的响应

javascript - AngularJs 指令不工作/不可见

angularjs - 在 Angular 中设置和覆盖请求 header 的正确方法

当模型在 javascript 中更改时,AngularJS ng-checked 不会更新复选框