0

I’m using HttpInterceptors and also Lazy loading modules. I’ve been providing the interceptors only in my main app.module, which seemed to be what was recommended in the docs, and also seemed to work. But a separate package I’d like to add (ngx-sharebuttons) seems to be causing the interceptors not to trigger when I import it in a lazy loaded module; The ngx-sharebuttons package’s module imports HttpClientModule itself, which could be part of the issue.

Should I be re-providing the interceptors in every lazy loaded module that relies on them (or at least on the modules that also rely on ngx-sharebuttons)? If I re-provide my interceptors, is there any risk that they will run twice on a single request?

Karptonite
  • 1,490
  • 2
  • 14
  • 30
  • How do you determine if it got triggered or not? What does it look like? Are you expecting all modules to share the same instance (in which case see https://stackoverflow.com/questions/39672816/can-lazy-loaded-modules-share-the-same-instance-of-a-service-provided-by-their-p)? – jonrsharpe Oct 16 '17 at 14:36
  • My interceptor adds prefixes to requests to direct them to a separate API service. If the prefix is not added, that means that the interceptor is not triggered. I'm expecting to be able to import the HttpClientModule once in my root app, as suggested here: https://angular.io/guide/http#setup-installing-the-module. I'm a little murky on what happens when an interceptor is provided, hence my question, but providing it once in the root app has worked up until this point. – Karptonite Oct 16 '17 at 14:53

0 Answers0