import { Injectable } from '@angular/core' ; import { HttpEvent , HttpInterceptor , HttpHandler , HttpRequest } from '@angular/common/http' ; import { Observable } from 'rxjs/Observable' ; import { AuthService } from './auth.service' ; @ Injectable ( ) export class HeaderInterceptor implements HttpInterceptor { constructor ( private auth ) { } intercept ( req , next ) { const authHeader = this . auth . getAuthorizationHeader ( ) ; const headers = req . headers . set ( 'Authorization' , authHeader ) . set ( 'Content-Type' , 'application/json' ) ; const authReq = req . clone ( { headers } ) ; return next . handle ( authReq ) ; } }