如何将ngbDropdown添加到bootstrap 4 navbar

h5qlskok  于 2023-11-15  发布在  Bootstrap
关注(0)|答案(3)|浏览(167)

我使用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>

字符串
问题“下拉菜单”无法展开

oyjwcjzk

oyjwcjzk1#

很难看到你的特定项目中发生了什么,因为我刚刚复制和粘贴了你的代码,它工作得很好,检查这个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 {}

wz8daaqr

wz8daaqr2#

最后,我把它作为Bootstrap 5。

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Your App</a>

  <ul class="navbar-nav">
    <li class="nav-item">
      <a class="nav-link" href="#">Home</a>
    </li>

    <!-- Dropdown Menu -->
    <li ngbDropdown class="nav-item">
      <a
        class="nav-link"
        id="dropdownMenu"
        ngbDropdownToggle
      >
        Dropdown
      </a>
      <div ngbDropdownMenu aria-labelledby="dropdownMenu">
        <a ngbDropdownItem href="#">Item 1</a>
        <a ngbDropdownItem href="#">Item 2</a>
        <a ngbDropdownItem href="#">Item 3</a>
      </div>
    </li>
  </ul>
</nav>

字符串

pqwbnv8z

pqwbnv8z3#

如果你想你的导航栏切换,看看这个;

<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">
    &#9776;
</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)。

相关问题