Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@HostListener is not performing click event

Tags:

angular

I have added a dropdown and trying to open it using directive but click is not working with @HostListener. Below is my angular and html code.

import { Directive, HostListener, HostBinding } from '@angular/core';
@Directive({
  selector: '[appDropdowndirective]'
})
export class DropdowndirectiveDirective {

  constructor() { }

  @HostBinding('class.open')
  isOpen = false;

  @HostListener('click', ['$event'])
  toggleOpen(){
    this.isOpen = !this.isOpen;
  }

}

HTML:

<div class="dropdown" appDropdowndirective>
    <button class="dropdown-toggle btn btn-primary">Kontakt und Support
        <i class="fa fa-angle-down" aria-hidden="true"></i>
    </button>
    <ul class="dropdown-menu">
        <li><a href="#">Kontakt und Support</a></li>
        <li><a href="#">Kontakt und Support</a></li>
        <li><a href="#">Kontakt und Support</a></li>
    </ul>
</div>
like image 836
Mahesh Sharma Avatar asked Mar 08 '23 06:03

Mahesh Sharma


1 Answers

Usually when I get something like that it is because I forgot to register the directive in my module

like image 194
Jason Avatar answered Mar 19 '23 10:03

Jason