close div when click outside angular

PRs welcome! Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. To learn more, see our tips on writing great answers. Straight and to the point. It's not them. How do I toggle a class for only one reused (but not repeated) element in Angular 1? and make sure the defaultValue of mouseInFilter is false; and when dropdown should be visible mouseInFilter is going to be true. I check it and it works well (i only copy clickOutside.directive.ts to my project). Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. The accepted answer will throw an error if you click on the button to close the drawer/popup, and the button is located outside of it, because $apply() will be executed twice. Retrieve the position (X,Y) of an HTML element. rev2023.5.1.43405. Thanks for contributing an answer to Stack Overflow! Close the main div after button click in angular 2 - Stack Overflow What are the advantages of running a power tool on 240 V vs 120 V? Menu has to close only when i click outside of it. It possible to click outside an element to close it on Blazor? How can I close a dropdown on click outside? Folder's list view has different sized fonts in different folders. Could you possibly explain further? By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. What differentiates living as mere roommates from living in a marriage-like relationship? So, if you want to achieve the same functionality without attaching global document listener, you may consider as a valid the following example. The other answers worked in some cases for me, except sometimes my dropdown closed when I interacted with elements within it and I didn't want that. You can, for example, subscribe whenever the popup gets toggled via a click and start listening for "outside clicks" only then.

Police Chase Today Birmingham, Articles C