How to share an object for two parallel level components?


#1

Case: I need to share an object for two parallel level components, once the components are destroyed the object reference should be destroyed. Now I used service for sharing sharing but I need it should not be a long-lived state. Any alternative solution for this. I’m in a situation to initialise both the components using util method so, I couldn’t not use block form initialisation for component. It would be helpful If I just replace service as some other object and use it.


#2

Introduce a parent component that wraps both and put the data in the parent.

That way both components have access to it and when you destroy the parent, everything gets destroyed.