Angular HttpClient的fetch保持活动标志的类似功能

huangapple go评论61阅读模式
英文:

Angular HttpClient analogue for fetch keepalive flag

问题

我正在开发一个Angular应用程序,使用它的HttpClient。我发现fetch() Api支持有用的keepalive选项,以保持连接在HTML页面的生存时间之外。

fetch(someUrl, {
  method: 'POST',
  body: data,
  keepalive: true,
});

当使用HttpClient时,我似乎找不到类似的东西。这个选项是否存在?

英文:

I am developing an Angular application using its HttpClient. I found that fetch() Api does support the useful keepalive option to maintain the connection beyond the livetime of the html page.

fetch(someUrl, {
  method: 'POST',
  body: data,
  keepalive: true,
});

I cant seem to find anything similar when using HttpClient. Does this option exist at all?

答案1

得分: 1

默认情况下,HttpModule 不依赖于 fetch API,而是依赖于 XHR。

所以,答案是否定的。

自从16.1版本以后,你可以使用 withFetch() 切换到基于 fetch API 的实现,但它也不支持 keepAlive 选项。

不过,你可以提出一个功能请求

英文:

By default the HttpModule does not rely on the fetch API but the XHR.

So no, there is no such option.

Since 16.1, you can use withFetch() to switch to the fetch API base implementation but it doesn't support the keepAlive option either.

You could open a feature request though.

huangapple
  • 本文由 发表于 2023年7月20日 22:36:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730983.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定