I am trying to create a directive for a drop-down, as long as I am working with single one it works like a charm. I can spot click outside dropdown using following code:
@HostListener('document:click', ['$event'])
onDocumentClick(event: any): void {
console.log("document click");
// close
}
@HostListener('click')
onClick(): void {
console.log('click on ');
// toggle
}
The problem occurs when there are 2 dropdowns created. I would like close first drop-down when second is opened, however when I click on the second dropdown, only "click" event is getting triggered and "document.click" is not getting executed. I would expect that both events should occur unless I explicitly use preventDefault on click but apparently this happens automatically.
What should be correct approach in Angular 5 to close first drop-down when second is opened?