Injection Tree Inheritance #998

Closed
opened 2025-08-09 17:18:29 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @rpampin on 2/21/2017

As indicated at Angular 2 Docs, if one includes a provider on AppModule, every single child module should inherit those services.

Here's a plnkr I've made pretty quick. I have a service that function as an http interceptor. Inside I create a random seed to see if the service is created anew when a lazy module is loaded. If you run this code, changing from HomeComponent to LazyComponent and clicking on Request, on the console I get the same seed value. So it seems to work as advertised.

Now I'm trying to do the same thing with aspnetcore-spa. The first thing I did was add angular2-router-loader to load lazy modules with webpack, but the injector is not inherited. If I make any Http call inside a component of my LazyModule, nothing is intercepted. Whereas I make a request inside an eager loaded module, it works and with the same seed value.

I've tried adding the CoreModule to the LazyModule imports, but doing so creates a new instance of the interceptor service.

Is this something that should be working and it isn't, or am I missing something?

*Originally created by @rpampin on 2/21/2017* As indicated at Angular 2 Docs, if one includes a provider on AppModule, every single child module should inherit those services. Here's a [plnkr](https://plnkr.co/edit/GCBRgpgsAMoiP4i0FRCQ) I've made pretty quick. I have a service that function as an http interceptor. Inside I create a random seed to see if the service is created anew when a lazy module is loaded. If you run this code, changing from HomeComponent to LazyComponent and clicking on Request, on the console I get the same seed value. So it seems to work as advertised. Now I'm trying to do the same thing with aspnetcore-spa. The first thing I did was add **angular2-router-loader** to load lazy modules with webpack, but the injector is not inherited. If I make any Http call inside a component of my LazyModule, nothing is intercepted. Whereas I make a request inside an eager loaded module, it works and with the same seed value. I've tried adding the CoreModule to the LazyModule imports, but doing so creates a new instance of the interceptor service. Is this something that should be working and it isn't, or am I missing something?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#998
No description provided.