Angular 17 Interceptor Not Intercepting Requests? Common Pitfalls and Fixes for Standalone Components

Angular 17 interceptors fail when they aren't registered in the root injector that supplies HttpClient, most commonly caused by missing provideHttpClient() in bootstrapApplication or forgetting multi: true on the HTTP_INTERCEPTORS token.

Angular 17’s shift to standalone components changes how you register HTTP interceptors compared to the classic NgModule pattern. Since interceptors rely on the HTTP_INTERCEPTORS multi-provider token defined in packages/common/http/src/interceptor.ts, any misconfiguration in the provider hierarchy causes the interceptor chain to be built without your class, resulting in requests that bypass your logic entirely.

Why Interceptors Fail in Angular 17 Standalone Apps

In the standalone API, there is no AppModule to import HttpClientModule into. Instead, HttpClient and its interceptor chain are configured through the provideHttpClient() function exported from packages/common/http/src/provider.ts. If you bootstrap with bootstrapApplication but omit this provider, Angular never instantiates the HttpClient service defined in packages/common/http/src/client.ts, and consequently never constructs the interceptor array.

Common Pitfalls When Setting Up Angular HTTP Interceptors

Missing provideHttpClient() in bootstrapApplication

When migrating to standalone components, developers often forget that HttpClientModule is no longer automatically available. Without calling provideHttpClient() (or importProvidersFrom(HttpClientModule)) in the providers array of bootstrapApplication, the HTTP_INTERCEPTORS token is never registered in the root injector.

import { bootstrapApplication } from '@angular/platform-browser';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { AppComponent } from './app/app.component';
import { AuthInterceptor } from './app/auth.interceptor';

bootstrapApplication(AppComponent, {
  providers: [
    provideHttpClient(withInterceptorsFromDi()),
    { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }
  ]
});

Forgetting to Import HttpClientModule in Standalone Components

If you are mixing standalone components with the module-based approach, any standalone component that directly injects HttpClient must import HttpClientModule in its imports array. As defined in packages/common/http/src/module.ts, this module provides the HttpClient service and initializes the interceptor chain.

@Component({
  selector: 'app-data',
  standalone: true,
  imports: [HttpClientModule], // Required for HttpClient injection
  template: `...`
})
export class DataComponent {
  constructor(private http: HttpClient) {}
}

Omitting multi: true on HTTP_INTERCEPTORS Provider

The HTTP_INTERCEPTORS token is a multi-provider array. If you omit multi: true, your interceptor overwrites the previous provider instead of appending to the chain. This is a silent failure where only the last-registered interceptor runs.

// Wrong - overwrites previous interceptors
{ provide: HTTP_INTERCEPTORS, useClass: MyInterceptor }

// Correct - adds to the chain
{ provide: HTTP_INTERCEPTORS, useClass: MyInterceptor, multi: true }

Registering Interceptors in Component Providers

Component-level providers create a child injector scoped to that component. Since HttpClient is typically provided at the root level, it cannot see interceptors registered in a component’s providers array. Always register interceptors globally in bootstrapApplication or a root-level module.

Lazy Loading Module Providers vs. Standalone Root

If you provide an interceptor inside a lazy-loaded NgModule while your root app uses standalone bootstrapping, the lazy-loaded providers are isolated. The HttpClient instance at the root level never receives the interceptor. Move the interceptor registration to the root providers array or use provideHttpClient with withInterceptorsFromDi() at the bootstrap level.

Interceptor Order and HttpClient Consumption Timing

The interceptor chain is built in the order providers are registered. If a service that injects HttpClient is provided before your interceptor, that service receives an HttpClient instance built without your interceptor. Place interceptor registrations before other services in the providers array, or ensure they are registered via provideHttpClient which handles ordering internally.

Modifying Requests Without Cloning

Interceptors must treat HttpRequest objects as immutable. If you modify the request directly instead of calling req.clone(), downstream interceptors and the final HttpHandler receive the original, unmodified request. Always clone when adding headers or changing the URL.

intercept(req: HttpRequest<any>, next: HttpHandler) {
  // Wrong - modifies original request
  req.headers.set('X-Auth', 'token');
  
  // Correct - creates immutable clone
  const authReq = req.clone({
    setHeaders: { 'X-Auth': 'token' }
  });
  return next.handle(authReq);
}

Injecting HttpClient Into the Interceptor

Creating a circular dependency by injecting HttpClient into an interceptor causes Angular to silently abort interceptor registration. If you need to make HTTP calls inside an interceptor (e.g., for token refresh), inject HttpBackend instead and create a local HttpClient instance, or use a separate service that doesn't trigger the interceptor chain.

Correct Setup for Angular 17 Standalone Interceptors

To ensure your interceptor catches every request in an Angular 17 standalone application, follow this pattern:

  1. Define your interceptor implementing HttpInterceptor from @angular/common/http
  2. Register it globally using provideHttpClient(withInterceptorsFromDi()) and the HTTP_INTERCEPTORS multi-provider token
  3. Ensure multi: true is set on the provider
// main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { provideHttpClient, withInterceptorsFromDi, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AppComponent } from './app/app.component';
import { LoggingInterceptor } from './app/logging.interceptor';

bootstrapApplication(AppComponent, {
  providers: [
    provideHttpClient(withInterceptorsFromDi()),
    { provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptor, multi: true }
  ]
});
// logging.interceptor.ts
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable()
export class LoggingInterceptor implements HttpInterceptor {
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    console.log(`Outgoing request to ${req.url}`);
    return next.handle(req);
  }
}

Summary

  • Angular 17 standalone apps require explicit registration of HttpClient via provideHttpClient() in bootstrapApplication; the classic HttpClientModule import alone is insufficient.
  • Interceptors must be registered globally using the HTTP_INTERCEPTORS multi-provider token with multi: true; component-level providers or lazy-loaded module providers will not work.
  • Order matters: Register interceptors before any service that injects HttpClient to ensure they are included in the chain.
  • Immutability is required: Always clone HttpRequest objects using req.clone() when modifying headers or URLs.
  • Avoid circular dependencies: Never inject HttpClient into an interceptor; use HttpBackend if you need to make sub-requests.

Frequently Asked Questions

Why is my interceptor not running in Angular 17 standalone mode?

Your interceptor is likely not registered in the root injector that supplies HttpClient. In Angular 17 standalone applications, you must call provideHttpClient(withInterceptorsFromDi()) in the providers array of bootstrapApplication, then register your interceptor using { provide: HTTP_INTERCEPTORS, useClass: YourInterceptor, multi: true }. Without provideHttpClient, Angular never instantiates the HttpClient service defined in packages/common/http/src/client.ts, so the interceptor chain is never built.

Do I still need multi: true for HTTP_INTERCEPTORS in Angular 17?

Yes. The HTTP_INTERCEPTORS token is defined as a multi-provider token in packages/common/http/src/module.ts. Omitting multi: true causes your interceptor provider to overwrite any previously registered interceptors instead of appending to the array. This results in only the last-registered interceptor executing, while earlier ones (including yours) are silently discarded.

Can I provide an interceptor in a component's providers array?

No. Component-level providers create a child injector scoped to that specific component instance. Since HttpClient is typically provided at the application root level (via provideHttpClient or HttpClientModule), it exists in the root injector and cannot see interceptors registered in child injectors. Always register interceptors globally in bootstrapApplication or your root AppModule to ensure they are part of the interceptor chain processed by HttpClient.

How do I order multiple interceptors in Angular 17?

Interceptors execute in the order they are registered in the DI providers array. When using provideHttpClient(withInterceptorsFromDi()), Angular collects all HTTP_INTERCEPTORS providers in the order they appear in the providers array. Place logging, error handling, or authentication interceptors early in the array to ensure they wrap subsequent interceptors. If you register a service that injects HttpClient before your interceptor providers, that service receives an HttpClient instance built without your interceptor, so always register interceptors before other HTTP-dependent services.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →