I'm using Bootstrap 3 to follow a tutorial but they create their own menu, so I was wondering how I could use bootstraps hamburger menu. I have a directive for dropdowns, but it doesn't work when I place it on the button tag or anywhere else.
I don't want to use jquery or bootstrap.js, but only Angular tools.
This is the HTML template.
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header" appDropdown>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false" appDropdown>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">Salsa @ Rio</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav" appDropdown>
<li class="dropdown" appDropdown>
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Courses <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a routerLink="/courses/0">Salsa 1</a></li>
<li><a routerLink="/courses/1">Salsa 2</a></li>
<li><a routerLink="/courses/2">Salsa 3</a></li>
<li role="separator" class="divider"></li>
<li><a routerLink="/courses/3">Cuban Salsa Starter</a></li>
<li><a routerLink="/courses/4">Cuban Salsa Foundation</a></li>
<li><a routerLink="/courses/5">Cuban Salsa 1</a></li>
<li><a routerLink="/courses/6">Cuban Salsa 2</a></li>
</ul>
</li>
This is the directive:
export class DropdownDirective {
@HostBinding('class.open') isOpen = false;
@HostListener('document:click', ['$event']) toggleOpen(event: Event) {
this.isOpen = this.elRef.nativeElement.contains(event.target) ? !this.isOpen : false;
}
constructor(private elRef: ElementRef) {}
}