How can I close a dropdown on click outside? This doesn't work when there is an element controlled by an ngIf inside the trigger element, since the ngIf removing the element from the DOM happens before the click event: does it work on a component that created dynamiclly via : const factory = this.resolver.resolveComponentFactory(MyComponent); const elem = this.vcr.createComponent(factory); This works perfectly with ngif or dynamic updates as well. Content Discovery initiative April 13 update: Related questions using a Review our technical responses for the 2023 Developer Survey. ', referring to the nuclear power plant in Ignalina, mean? What's the cheapest way to buy out a sibling's share of our parents house if I have no cash and want to pay less than the appraised value? How to remove close button on the jQuery UI dialog? I suggest adding a @Hostlistener() to the document click event only once inside your main app component. Thanks for contributing an answer to Stack Overflow! HTML :