DEV Community

Discussion on: That's why your Angular Interceptor may NOT WORK! šŸ˜„ [5 seconds fix]

joekaiser profile image
Joe • Edited on

OK, I must be missing the point or something. Take a look at this stack blitz

The interceptor is defined in the app.module, and the sub module is lazy loaded.

Click on the sub module link and check the console. The interceptor was run just fine.

What am I doing different?

Thread Thread
michaeljota profile image
Michael De Abreu

Nothing. I have never seen that problem before if you load CoreModule in AppModule once.

Thread Thread
bartosz_io profile image
Bartosz Pietrucha Author

Joe, first of all thank you for taking the time to dig deeper into this topic. I need to apologize you. You are 100% right. Since you have HttpClientModule imported at the root level (app module), all is fine. The problem I faced was caused by the fact, that I imported HttpClientModule the second time in the SharedModule... šŸ˜„. This really confused me and I am sorry. Finally, I believe the best way is to import HttpClientModule once (in the AppModule or CoreModule).

Again, thanks! I will update the article. Best,

Thread Thread
joekaiser profile image

It's how we learn, friend! :)