NG.VII · Angular 22 practice question

What does adding withXhr() inside provideHttpClient(withXhr()) do in an Angular 22 application?

export const appConfig: ApplicationConfig = {
  providers: [provideHttpClient(withXhr())],
};
Choose one answer
Check answer and explanation

Correct answer: It switches HttpClient from the default fetch backend to XMLHttpRequest.

Explanation

HttpClient uses the fetch API by default, and passing withXhr() switches it to use XMLHttpRequest instead.

Common trap

Older Angular versions defaulted to XMLHttpRequest and used withFetch(), which is the opposite of Angular 22's default. withXhr() replaces the fetch backend with XMLHttpRequest rather than running both in a fallback chain.

Source: Angular docs: Setting up `HttpClient` — `withXhr`
Checked against the cited text on 2026-11-25.

Report an error in this question