In my Angular4 app I created a standard nav bar. When the screen size decreases the nav menu dropdown appears. When clicking on the menu dropdown, the (collapsed) links are not shown.
Question: how can I get the menu dropdown working for Angular 4 + Bootstrap 3?
I created a standard component. This is the template file:
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a routerLink="/search" class="navbar-brand">Brand-name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a routerLink="/search">Search</a></li>
<li><a routerLink="/edit">Edit</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a routerLink="/signup">Signup</a></li>
</ul>
</div>
</div>
</nav>
Of course I read similar questions and articles, but none helped me any further. Most are about Boostrap only, not the combination with Angular 4.
All answers so far show how to open the dropdown menu. The answers don't show how to collapse that dropdown menu again after selecting on a menu item.
Thanks to Thomas Rundle the basic parts can be found in the following solution. I added some code. The header.component.ts is:
The template header.component.html is:
https://plnkr.co/edit/oSKnNWXNafbMjCiPwqrv?p=preview
since you have target="#navbar", you have to set the id of the target to navbar for it to work.
The Bootstrap Drop down adds a class open to the
<ul>
element for the drop down to appear and close , you can make use of Angular Directives to add the Same behaviour to the Component.App Drop Down Directive
Stick it to your ul
<ul class="nav navbar-nav" appDropdown>
A working Example Code