Skip to content

Instantly share code, notes, and snippets.

@GerritRiesch94
Created July 10, 2023 13:33
Show Gist options
  • Save GerritRiesch94/e762a2bb3345de4cd816e044fd9a5dc9 to your computer and use it in GitHub Desktop.
Save GerritRiesch94/e762a2bb3345de4cd816e044fd9a5dc9 to your computer and use it in GitHub Desktop.
Interceptor new way
import { bootstrapApplication } from "@angular/platform-browser";
import { AppComponent } from "./app/app.component";
import { HttpHandlerFn, HttpRequest, provideHttpClient, withInterceptors } from "@angular/common/http";
import { provideRouter } from "@angular/router";
import { inject } from "@angular/core";
import { HeaderService } from "./app/header.service";
import { MY_ROUTES } from "./app/app.routes";
bootstrapApplication(AppComponent, {
providers: [
provideHttpClient(
withInterceptors([
(request: HttpRequest<any>, next: HttpHandlerFn) => {
const header = inject(HeaderService).getHeader();
return next(request.clone({setHeaders: {'MyHeader': header}}));
}
]),
),
provideRouter(MY_ROUTES),
]
}
).catch(err => console.error(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment