I am trying to use a Directive to activate dropdown menu in my Angular project. The class "open" has been deprecated since bootstrap 3 but I am currently using bootstrap 5 and how to use 'show' class instead of 'open'?
my Directive:
import { Directive, HostListener } from '@angular/core';
@Directive({
selector: '[appDropDown]',
})
export class DropDownDirective
{
@HostBinding('class.open') isOpen = false;
@HostListener('click') toggleOpen() {
this.isOpen = !this.isOpen;
}
constructor() {}
}
my HTML snippet from a component:
<div
class="btn-group"
appDropDown>
<button
type="button"
class="btn btn-primary dropdown-toggle ">
Manage Recipe <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">To Shopping List</a></li>
<li><a href="#">Edit Recipe</a></li>
<li><a href="#">Delete Recipe</a></li>
</ul>
</div>
</div>
Thanks.
One possibility might be to add a rule to the component or global CSS:
I suspect your HostBinding + Hostlistener is applying the class "open" to the div where your HostBinding selector is. This in itself is probably not enough with the CSS rules you currently have in your project to show the dropdown.
In order to solve a similar problem with Angular itself and not with simple CSS rules I did the following: