1

The navbar collapse is not working on small screens. I click on the button that appears on the right side for the menu, but nothing happens. I have looked up other solutions, and changed my angular.json file.

"scripts": [
    "node_modules/jquery/dist/jquery.min.js",
    "node_modules/bootstrap/dist/js/bootstrap.min.js"
]

Here is my .html code:

<header class="navbar bg-main-bg pt-0 pb-0 mt-0 mb-0" style="z-index: 1000; height: 80px;">
    <nav class="container navbar-expand-md h-100">
        <a class="navbar-brand" href="#" style="margin-right: 120px; height: 50px;">
            <app-coin [width]="50" [height]="50" text="A"></app-coin>
            <h1 class="position-relative text-txt-h" style="line-height: 50px; left: 52px;">LBAR</h1>
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggler" aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div id="navbarToggler" class="collapse navbar-collapse h-100">
            <ul class="navbar-nav h-100 text-uppercase">
                <li class="nav-item">
                    <a class="nav-link h-100 pr-5 pl-5" routerLinkActive="active" [routerLinkActiveOptions]="{exact:true}" routerLink="/">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link h-100 pr-5 pl-5" routerLinkActive="active" routerLink="/work">Work</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link h-100 pr-5 pl-5" routerLinkActive="active" routerLink="/contact">Contact</a>
                </li>
            </ul>
        </div>
    </nav>
</header>

However, it still does not seem to work. When the screen shrinks, the links to the pages disappear, and the icon that usually causes the links to appear is not working. I know of the solution where you set the collapse value here, but that does not work either. Is there any way to get the navbar collapse working?

Ripper
  • 97
  • 8
  • I recommend to use [ng-bootstrap](https://ng-bootstrap.github.io) when combining Angular and Bootstrap. It will make your life a way easier. – jmac Jul 19 '22 at 21:29

1 Answers1

0

Besides the use of ng-boostrap, i had to use the solution provided here https://www.youtube.com/watch?v=m5fdwxB-jIM

In sumary the code must me changed in the html file to:

<button class="navbar-toggler" type="button" (click)="isCollapsed = !isCollapsed" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
    aria-controls="navbarSupportedContent" [attr.aria-expanded]="!isCollapsed" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent" [ngbCollapse]="isCollapsed">

and in the .ts file

  public isCollapsed : boolean = true;