On an app with a lot of different components within one component I have a custom Auto-suggest box. The box should be closed if the user clicks anywhere but on the Auto-suggest box (or containing elements of the auto-suggest box).
This is what I would do in jQuery:
$(document).on('click','body',function(e) {
if(e.target!='.suggestbox' && $(e.target).parent('.suggestbox').length <1 ) {
$('.suggestbox').remove();
}
});
However In my Angular Dart templates I have:
index.html:
<body>
<my-app>
// sub component
// sub sub component
</my-app>
</body>
I can think of a possibility in detecting a click on the topmost wrapper within the my-app component and send the action to the subcomponent but this is still not a body click.
What is the best way to solve this?
not tested and the button and div element are only a rough approximation of what the component would look like.
See also How can I close a dropdown on click outside?
update
Angular 5 doesn't support global event handlers like
document:...
Use instead the imperative variant