我使用ng-bootstrap Angular 2。
<nav class="navbar navbar-fixed-top navbar-dark bg-inverse">
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<div ngbDropdown>
<button class="btn" ngbDropdownToggle>Projects</button>
<div class="dropdown-menu">
<button class="dropdown-item" >AA</button>
</div>
</div>
</li>
</ul>
</nav>
问题&#34;下拉菜单&#34;无法扩展
答案 0 :(得分:2)
我很难看到你的特定项目中发生的事情,因为我刚刚复制了这个项目。粘贴你的代码,它工作得非常好,检查这个plunker:http://plnkr.co/edit/CFntB5mkshJ97x1aIGU1?p=preview
您可能想要验证是否正确导入(import {NgbModule} from '@ng-bootstrap/ng-bootstrap'
)添加NgbModule
模块:
@NgModule({
imports: [ BrowserModule, NgbModule ],
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}
答案 1 :(得分:0)
如果您希望导航栏可以切换,请检查一下;
<nav class="navbar navbar-dark bg-inverse">
<button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#navExample" aria-controls="navExample" aria-expanded="false" aria-label="Toggle navigation">
☰
</button>
<div class="collapse navbar-toggleable-xs" id="navExample">
<ul class="nav navbar-nav">
<li class="nav-item">
<a href="#" class="nav-item nav-link">First link</a>
</li>
<li class="nav-item">
<a href="#" class="nav-item nav-link">Second link</a>
</li>
</ul>
</div>
如果您只需要导航栏中的下拉菜单,官方网站中的示例应该有效;
<div ngbDropdown class="d-inline-block">
<button class="btn btn-outline-primary" id="dropdownMenu1" ngbDropdownToggle>Toggle dropdown</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
<button class="dropdown-item">Action - 1</button>
<button class="dropdown-item">Another Action</button>
<button class="dropdown-item">Something else is here</button>
</div>
</div>
确保你的html文件包含bootstrap(我使用bootstrap 4)。