ng-bootstrap下拉位置不适用于7号角

时间:2019-06-29 14:56:01

标签: angular ng-bootstrap

我在Angular 7中使用ng-bootstrap创建了一个标准的引导菜单,并在右侧显示了链接,但是如果使用下拉菜单,它将显示在屏幕之外。 为了确保我不会弄乱代码,我进行了角度,引导程序(仅angular.json中的CSS代码)和ng-bootstrap的全新安装。我在AppModule中包含了NgbModule并尝试了以下代码:

<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="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-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" ngbDropdown placement="bottom-right">
        <a class="nav-link dropdown-toggle" ngbDropdownToggle href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" ngbDropdownMenu 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>
    </ul>
  </div>
</nav>

这是我看到的: Navbar with dropdown menu opened

1 个答案:

答案 0 :(得分:1)

您需要在具有display="dynamic"属性的元素上添加ngbDropdown

请参见the documentation