Created
July 10, 2023 13:33
-
-
Save GerritRiesch94/e762a2bb3345de4cd816e044fd9a5dc9 to your computer and use it in GitHub Desktop.
Interceptor new way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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