We can follow this approach Detect click outside element? in Angular as well with HostListner.
In my component I have registered a host listener which listens on document click and hide the menu inside my component. This approach works fine with a single component. However I am a bit concerned about the performance when the component is instantiated(in a list) 100 times each component registers document on click and do some processing to hide the menu opened from its component if any.
I can move the code outside the component list but then I need to hold references of each component to detect which one has opened menu and should be closed.
None of these two approach is perfect is there some other way to handle this efficiently as well as without leaking the component code in its parent?