Nicola Piccoli
Nicola Piccoli

Reputation: 135

ng-bootstrap dropdown placement not working with angular 7

I'm using ng-bootstrap with Angular 7 to create a standard bootstrap menu with links on the right but if I use a dropdown menu it goes out of the screen. To be sure I wasn't messing the code I did a clean installation of angular, bootstrap (just the css code in angular.json) and ng-bootstrap. I've included the NgbModule in AppModule and tried this code:

<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>

This is what I see: Navbar with dropdown menu opened

Upvotes: 2

Views: 4875

Answers (1)

JB Nizet
JB Nizet

Reputation: 691685

You need to add display="dynamic" on the element with the ngbDropdown attribute.

See the documentation

Upvotes: 12

Related Questions