In Angular2, I am facing an issue with two components. When a user clicks a button in component1, a method is triggered that stores data in the shared service to a variable. However, component2's ngOnInit() method initializes this variable to undefined because it doesn't wait for the click event.
So, my question is: how can I make Angular2 component2 wait for the click event in component1?
Usually in JavaScript, we would use click event listeners or callback functions to achieve this, but I am unsure of how to implement the same concept in Angular.
I would appreciate any ideas or suggestions on how to approach this problem.