import { Injectable , Injector } from '@angular/core' ; import 'rxjs/add/operator/map' ; import { HttpEvent , HttpHandler , HttpInterceptor , HttpRequest } from "@angular/common/http" ; import { Observable } from "rxjs/Observable" ; import { User } from "../user/user" ; import { timeout } from "rxjs/operator/timeout" ; @ Injectable ( ) export class JwtInterceptorProvider implements HttpInterceptor { private user : User ; constructor ( private inj ) { console . log ( 'Hello JwtInterceptorProvider Provider' ) ; } intercept ( req , next ) { this . user = this . inj . get ( User ) ; this . user . getToken ( ) . then ( token => { req = req . clone ( { setHeaders : { Authorization : token } } ) ; } ) ; return next . handle ( req ) . map ( event => { return event ; } ) ; } }