我正在尝试在窗口大小减半时创建导航栏下拉列表。下拉列表在窗口宽度为950px时不起作用,但它在窗口宽度为768px时起作用。
navbar.component.html
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" (click)="toggleMenu()">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav" [ngbCollapse]="isCollapsed">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
navbar.component.ts
import { Component } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html'
})
export class NavbarComponent {
public isCollapsed = true;
toggleMenu() {
this.isCollapsed = !this.isCollapsed;
}
}
在950px下拉列表不会隐藏菜单项。但是,如果我取消选中“.navbar-collapse.collapse”类的'display:block!important',那么它可以工作。
答案 0 :(得分:0)
我不确定这可以作为“解决方案”,但希望这会有助于其他人。我从ng-bootstrap切换到ngx-bootstrap并使用相同的组件(Collapse)解决了我的问题。