import { Injectable } from '@angular/core' ; import { HttpEvent , HttpHandler , HttpInterceptor , HttpRequest } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { LoginService } from './login.service' ; @ Injectable ( ) export class AuthInterceptor implements HttpInterceptor { constructor ( private loginService ) { } intercept ( request , next ) { const auth = this . loginService . getAuthHeader ( ) ; if ( auth ) { request = request . clone ( { setHeaders : { Authorization : auth , } } ) ; } return next . handle ( request ) ; } }