I have used the following approach several times in my projects in order to pass data from one component to another. However, this time I have 2 component: parent (in AppModule) and sidebar (in CoreModule) components and I am trying to pass data from parent to sidebar on a dropdown change. However, it does not work and the subscribe
method on the sidebar component (in the example child component) is not triggered except from initial loading. Does being on different modules cause this problem? Or any other issue about that?
Here is the DEMO.
Update:
Here is my module relationship:
parent.module:
imports: [
SharedModule
],
providers: []
child.module:
imports: [
SharedModule
],
providers: []
shared.module:
providers: [
DataService
]
When I update as shown above, it still does not work. However, if I move DataService
in the providers field from shared.module
to app.module
it works. But I think it should work when it is only in shared.module
as shown above. Why?