I am using a http interceptor in my angular project. I have a variable that I want to change at runtime that I can add various headers to. The basic setup of my interceptor is below
export class HeaderInterceptor implements HttpInterceptor {
public additionalHeaders: KeyValuePair[]
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {.....
}
I am initializing this in my module as follows.
providers: [{ provide: HTTP_INTERCEPTORS, useClass: HeaderInterceptor, deps: [AppConfigProvider, Router], multi: true }]
This all works fine but I cant think of a way to change the additionalHeaders property once the application is loaded. Is there a way to inject the interceptor into a component or perhaps a better way to do this altogether?