provideHttpClient()
Registers the HttpClient and optional interceptor/fetch features.
Syntax
provideHttpClient(...features): EnvironmentProviders Parameters
| Name | Type | Required | Description |
|---|---|---|---|
features | HttpFeature[] | No | Optional features like withInterceptors, withFetch. |
Returns
EnvironmentProviders — Providers enabling HttpClient.
Examples
import { provideHttpClient, withInterceptors, withFetch } from '@angular/common/http';
import { authInterceptor } from './auth.interceptor';
export const appConfig = {
providers: [
provideHttpClient(
withFetch(),
withInterceptors([authInterceptor]),
),
],
};
Notes
Replaces HttpClientModule. withFetch() switches to the Fetch API (good for
SSR), and withInterceptors registers functional interceptors. Add to
bootstrapApplication providers; then inject(HttpClient) anywhere.