title: How to create an angular library that intercepts http requests made from my app
body: <p>I am trying to create an angular library that intercepts http requests from the app it is imported in.
  The issue is that the interceptor doesn't work if it is imported from the library but if I move it inside my app it is working.</p>
  
  <p>the interceptor code from my library looks like this:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
  import { Observable, throwError} from 'rxjs';
  import { catchError } from 'rxjs/operators';
  
  @Injectable()
  export class SimpleInterceptor implements HttpInterceptor {
      constructor () {}
  
      intercept(request: HttpRequest&lt;any&gt;, next: HttpHandler): Observable&lt;HttpEvent&lt;any&gt;&gt; {
          return next.handle(request).pipe(catchError(err =&gt; {
              return throwError(err);
          }))
      }
  }
  </code></pre>
  
  <p>I'm importing the interceptor in my app like this (app.module.ts):</p>
  
  <pre><code>import { NgModule } from '@angular/core';
  import { HttpClientModule, HttpClient } from '@angular/common/http';
  import { TranslateCompiler, TranslateLoader, TranslateModule} from '@ngx-translate/core';
  import { TranslateHttpLoader } from '@ngx-translate/http-loader';
  import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler';
  
  import { HTTP_INTERCEPTORS } from '@angular/common/http';
  import { SimpleInterceptor } from '@myname/angular-simple-library';
  
  export function createTranslateLoader(http: HttpClient) {
    return new TranslateHttpLoader(http, 'languages/', '.json');
  }
  
  @NgModule({
    declarations: [],
    imports: [
      HttpClientModule,
      TranslateModule.forRoot({
        loader: {
            provide: TranslateLoader,
            useFactory: createTranslateLoader,
            deps: [HttpClient]
        },
        compiler: {
            provide: TranslateCompiler,
            useClass: TranslateMessageFormatCompiler
        }
      })
    ],
    providers: [
      { provide: HTTP_INTERCEPTORS, useClass: SimpleInterceptor, multi: true },
    ]
  })
  export class AppModule {}
  </code></pre>
  
  <p>Any ideas of what could go wrong here?
  Thank you!</p>