Angular detected that `HttpClient` is not configured to use `fetch` APIs. (Angular 17 - SSR)
回答 2
浏览 2353
2023-11-19
更新到 Angular 17 后出现此错误:
NG02801: Angular detected that `HttpClient` is not configured to use `fetch` APIs. It's strongly recommended to enable `fetch` for applications that use Server-Side Rendering for better performance and compatibility. To enable `fetch`, add the `withFetch()` to the `provideHttpClient()` call at the root of the application.
我认为在编写服务代码并通过注入函数导入HttpClient
之后,情况就会变成这样。
2 个回答
#1楼
已采纳
得票数 5
NG02801
不是错误,而是警告,鼓励开发人员启用 HttpClient
的 fetch 实现。
为此,只需在 app.config.ts
中调用 provideHttpClient(withFetch())
即可。
#2楼
得票数 -1
用这个
import { provideHttpClient, withFetch } from '@angular/common/http';
export const appConfig: ApplicationConfig = {
providers: [provideHttpClient(withFetch()), provideRouter(routes), provideClientHydration()]
};