Вы можете использовать HttpInterceptor для добавления дополнительных заголовков к каждому исходящему http-запросу.
@Injectable({
providedIn: 'root'
})
export class OutgoingInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
interceptedRequest = req.clone({
setHeaders: {
// These headers is for Passport authentication.
// You might to change these headers as you need
// Also you need to store your token in localStorage etc.
Accept: 'application/json',
Authorization: tokenData
}
});
return next.handle(interceptedRequest);
}
}
И вам нужно добавить этот вновь созданный перехватчик в массив провайдеров вашего модуля:
providers: [
...
{
provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptor,
multi: true
}
]