The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Configure Angular’s HTTP client with provideHttpClient() in your application providers. The right place depends on whether the app uses standalone bootstrap or NgModule bootstrap; tests use a separate testing provider. Angular’s current guide says HttpClient is available for injection by default starting in Angular v21, while provideHttpClient(...) remains the way to add features such as interceptors or customize behavior. See Angular’s HttpClient setup guide.
Choose the setup for your Angular app
First check the project’s Angular version and bootstrap style. For current standalone applications, configure the client in the application configuration. For an NgModule-based application, add the provider to the application module’s providers array. Both approaches use provideHttpClient().
Standalone application configuration
Import provideHttpClient from @angular/common/http and add it to the providers in app.config.ts:
import { ApplicationConfig } from '@angular/core';
import { provideHttpClient } from '@angular/common/http';
export const appConfig: ApplicationConfig = {
providers: [provideHttpClient()],
};
With that provider configured, injectable services and other classes can inject HttpClient from @angular/common/http and use it to make requests.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall#1 Best Overall
NgModule application
For an application bootstrapped with NgModules, import provideHttpClient and include it in the application module’s providers array:
import { NgModule } from '@angular/core';
import { provideHttpClient } from '@angular/common/http';
@NgModule({
providers: [provideHttpClient()],
})
export class AppModule {}
In Angular v21 and later, the current guide says HttpClient is provided for injection by default. Use the provider helper when you need to configure client features. If you are updating a legacy application, check its Angular version and existing backend and interceptor setup before replacing HttpClientModule. Angular maps the older module to provideHttpClient(withInterceptorsFromDi(), withXhr()); that is not necessarily the configuration you want in a newer application.
Add only the HttpClient features you need
provideHttpClient(...) accepts optional features. A plain provideHttpClient() is the starting point; add configuration when your application has a specific requirement. The available options and their behavior are described in the setup guide.
withInterceptors([...])registers functional interceptors.withInterceptorsFromDi()enables class-based interceptors provided through dependency injection.withRequestsMadeViaParent()forwards requests from a child injector’s client to the parent client.withJsonpSupport()adds JSONP support. Angular advises preferring CORS where possible.withXsrfConfiguration(...)customizes the built-in XSRF configuration.withNoXsrfProtection()disables XSRF protection; do not use it casually.withXhr()selects the XMLHttpRequest backend instead of the default fetch backend.
Angular’s built-in XSRF protection is enabled by default. For server-side rendering (SSR), retain the default fetch backend under current guidance. Angular warns that server-side XHR support is deprecated, is intended for removal in Angular 23, and carries redirect-security and denial-of-service concerns.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsRegister interceptors deliberately
Interceptors let an application apply request or response handling across HTTP calls. Angular recommends functional interceptors because their ordering is more predictable, particularly in complex setups. Register them with withInterceptors([...]) inside provideHttpClient(...); requests pass through the list in the order specified. The interceptor guide covers the registration details.
provideHttpClient(
withInterceptors([firstInterceptor, secondInterceptor]),
)
For an existing class-based interceptor, opt in explicitly with withInterceptorsFromDi() and provide the class using the HTTP_INTERCEPTORS multi-provider. Declaring an interceptor class alone does not add it to the HttpClient chain. DI-based interceptors run in provider registration order, which can be difficult to predict in extensive hierarchical injector configurations.
Rank #4
When a child injector should use the parent client
A child injector that provides its own HttpClient configuration normally uses that client for its requests rather than inheriting the parent chain. To run the child’s local interceptors and then send requests through the parent client, add withRequestsMadeViaParent() to the child configuration. This requires an HttpClient in the parent injector; otherwise Angular reports a runtime error.
Configure the test client separately
In a TestBed, use provideHttpClientTesting() from @angular/common/http/testing. It installs a test backend that captures requests so tests can assert on them and flush controlled success or error responses. HttpTestingController can also verify that no unexpected requests were made. See Angular’s HTTP testing guide.
Best Value
If a test needs client features such as interceptors, provide the configured client first and the testing provider second. The testing provider replaces parts of the client configuration, so the order matters:
TestBed.configureTestingModule({
providers: [
provideHttpClient(withInterceptors([authInterceptor])),
provideHttpClientTesting(),
],
});
Keep this test-only provider in the testing setup rather than adding it to production application providers.
Quick Recap
Common setup mistakes to avoid
- Using an old setup recipe without checking the Angular version: the current guide says injection is provided by default from v21 onward, while older applications may need explicit provider configuration.
- Adding an interceptor class but not enabling DI interceptors: use
withInterceptorsFromDi()and register the class withHTTP_INTERCEPTORS, or migrate to a functional interceptor. - Reversing test provider order: place
provideHttpClient(...)beforeprovideHttpClientTesting(). - Creating multiple clients across injectors without planning request flow: a child configuration can replace the parent client for child requests; use
withRequestsMadeViaParent()when requests should traverse the parent chain. - Switching to XHR by habit: the default backend is fetch, and Angular’s current guidance warns against XHR for SSR.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




