DEV Community

Discussion on: Angular Http Mock Interceptor for mocked backend

Collapse
anetz89 profile image
Markus

Hi sandiz,
thank you for this interesting article! A small addon to your code:
Unless you do not need to intercept the standard http requests (to add a console log by using the HttpRequestInterceptor) you can modify your app.module.ts this way:
// ...
providers: [
...isMock ? [{
provide: HTTP_INTERCEPTORS,
useClass: HttpMockRequestInterceptor,
multi: true
}] : []
],
// ...

This assures that no interceptor is loaded in non-mock environments.