gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 20:31:54 24 4
gpt4 key购买 nike

当使用 $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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com