I’m new to angular, I wrote an interceptor to test Basic Authentication, the problem is that the interceptor is never called. So I tried to launch my application in debug mode and what I discovered that interceptor is not included in deployed pages.
Is it a logic behavior?
Here my Interceptor:
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class BasicAuthenticationHtppInterceptorService implements HttpInterceptor {
constructor() { }
intercept(req: HttpRequest<any>, next: HttpHandler) {
if (sessionStorage.getItem('username') && sessionStorage.getItem('token')) {
req = req.clone({
setHeaders: {
Authorization: JSON.stringify(sessionStorage.getItem('token'))
}})
}
return next.handle(req);
}
}
>Solution :
In your main module, you should have something like:
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: BasicAuthenticationHtppInterceptorService,
multi: true
}
],
bootstrap: [AppComponent]
See https://angular.io/guide/http-intercept-requests-and-responses for more explaination

