Directive example for opening and closing toggle on dropdown
import { Directive, ElementRef, Renderer2, HostListener, HostBinding } from '@angular/core';
@Directive({
selector: '[appDropDown]',
})
export class DropsownDirective{
@HostBinding('class.open') isopen = false;
@HostListener('mouseenter') onMouseEnter(){
this.isopen = !this.isopen;
}
@HostListener('mouseleave') onMouseLeave(){
this.isopen = !this.isopen;
}
}
Component add directive appDropDown
<div class="col-xs-12">
<div class="btn-group" appDropDown>
<button class="btn btn-primary dropdown-toggle">
Manage Movie <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">To watching List</a></li>
<li><a href="#">Edit Movie</a></li>
<li><a href="#">Delete Movie</a></li>
</ul>
</div>
Make sure to Include new directive in the
@NgModule declarations