I\'m trying to learn how to use HttpInterceptor to add a couple of headers to each HTTP request the app do to the API. I\'ve got this interceptor:
in your interceptor file
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
@Injectable()
export class fwcAPIInterceptor implements HttpInterceptor {
intercept (req: HttpRequest, next: HttpHandler): Observable> {
const auth = req.clone({
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Auth-Token': 'jwtToken'
})
});
return next.handle(auth);
}
**in app module**
import {HTTP_INTERCEPTORS} from '@angular/common/http';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [
{provide: HTTP_INTERCEPTORS, useClass: CustomHttpInterceptorService, multi: true},
],
bootstrap: [AppComponent]
})