Skip to content

Instantly share code, notes, and snippets.

@danielcrisp
Created July 25, 2017 13:28
Show Gist options
  • Save danielcrisp/3c966a81a6059f1f19d1421ef0d07f0b to your computer and use it in GitHub Desktop.
Save danielcrisp/3c966a81a6059f1f19d1421ef0d07f0b to your computer and use it in GitHub Desktop.
AppModule - Async HTTP Interceptors with Angular 4
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AppComponent } from '/app.component';
import { AuthService } from './auth.service';
import { TokenInterceptor } from './token.interceptor';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
CommonModule,
HttpClientModule
],
providers: [
AuthService,
// register TokenInterceptor as HttpInterceptor
{
provide: HTTP_INTERCEPTORS,
useClass: TokenInterceptor,
multi: true
}
]
})
export class AppModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment