Bootstrap 4 collapse navbar with Angular 4

前端 未结 1 1671
死守一世寂寞
死守一世寂寞 2020-12-10 09:36

I want to make a navbar using Bootstrap 4 and Angular 2 that collapses his content on a button when the width of the browser reaches some value. I achieve this, and when the

相关标签:
1条回答
  • 2020-12-10 09:57

    This stackblitz shows how you can implement the Bootstrap navbar with the ngbCollapse directive from ng-bootstrap, without using jQuery. The boolean flag isNavbarCollapsed is defined in the component class and its value is toggled by the button.

    <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
      ...
      <button class="navbar-toggler" type="button" (click)="isNavbarCollapsed = !isNavbarCollapsed">
          <span class="navbar-toggler-icon"></span>
      </button>
      <div [ngbCollapse]="isNavbarCollapsed" class="navbar-collapse">
        ...
      </div>        
    </nav>
    
    0 讨论(0)
提交回复
热议问题