I am working on a angular application. I have certain set of screens. I have a variable who's value will always be in integer. For some screens this variable value is 1 and for some it is 2.
I want to detect change in this variable. For example for screen 1, myVal is 1 and for screen 2, myVal becomes 2 and for screen 5, myVal again becomes 1. I want to open a pop up when myVal value is becomes 2 from 1. The problem I am facing is when I am on screen 4 and when I send my response from rabbitMq the value of myVal immediately becomes 1 and my pop up if condition doesnot get executed.
How can I do that?
imagine you has a service -remember that a service is shared while whole live of your application
Any component that inject the service and subscribe to variableChange(*) -you can use distinctuntilChange to make something only if change the value- like
receive a change from any another component that also inject the service in constructor and make a next
If you want, you can use a getter of the variable in the way
(*)e.g. we can has a main.app that inject the constructor and subscribe
Our main.component can be, e.g.
A component that has in the ngOnInit()
When was loaded in the router-outlet makes that the "app-header" appears. If out component has a button
When click the button the "app-header" disappears