Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Navbar not working correctly: AngularCLI

I included bootstrap into my angularcli project but when I try to include a navbar none of the elements are working correctly. I am using a standard boostrap navbar example from the website but it looks weird:

enter image description here

What is wrong with my project that is making the navbar not load correctly?

navbar.component.html

enter image description here

<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
  <button class="navbar-toggler navbar-toggler-right" 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>
  <a class="navbar-brand" href="#">Navbar</a>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-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">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="text" placeholder="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

.angular-cli.json

"styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "styles.css"
      ],
like image 461
FrankTheTank Avatar asked Feb 11 '18 19:02

FrankTheTank


1 Answers

navbar.component.html:

<nav class="navbar navbar-default">
   <div class="container-fluid">
      <div class="navbar-header">
         <button type="button" class="navbar-toggle" (click)="toggleNavbarCollapsing()">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
         </button>
         <a routerLink="/" class="navbar-brand">Navbar</a>
      </div>
      <div class="navbar-collapse" [class.collapse]="navbarCollapsed">
      ...

navbar.component.ts:

navbarCollapsed = true;

toggleNavbarCollapsing() {
    this.navbarCollapsed = !this.navbarCollapsed;
}
like image 126
Aleksandar Petrovic Avatar answered Oct 21 '22 07:10

Aleksandar Petrovic