I am trying to create a directive for a drop-down list, while I work with a single one, it works like a charm. I can specify a drop down list using the following code:
@HostListener('document:click', ['$event'])
onDocumentClick(event: any): void {
console.log("document click");
}
@HostListener('click')
onClick(): void {
console.log('click on ');
}
The problem arises when creating two drop-down menus. I would like to close the first drop-down menu when opening the second, however, when I click on the second drop-down list, only the "click" event fires, and "document.click" is not executed. I would expect both events to happen if I do not explicitly use preventDefault for a click, but apparently this happens automatically.
What should be the right approach in Angular 5 to close the first expansion when opening the second page?