Reputation: 896
I have an angular app (v5). On one of the pages there are two components (A and B). Component A has a grid which upon a cell click push the cell value to a rxjs subject. Component B subscribed to that subject and refresh its content accordingly. This flow works as expected until Component B is moved to a different routerlink.
Looking under the hood I can see that when the cell is clicked on component A, component B was indeed notified the change in its subscription (next) handler. Note at that time component B is not visible yet. When the component B is brought to visibility via the routerlink click it’s UI doesn’t reflect the value in the subject(observable).
Upvotes: 1
Views: 327
Reputation: 3730
You should use BehaviourSubject in this scenario. BehaviourSubject emits last value. So when you will subscribe in component B it will recieve last value emited by component A.
Hope it will help
Upvotes: 2