0

I am trying to operate bootstrap 4 with angular 6. I am testing to see if it works with Bootstrap's default navbar.

this is the code (Just copy-paste it from Bootstrap's components from their page):

<nav class="navbar navbar-default">
    <div class="container-fluid">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">Brand</a>
      </div>

      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
          <li><a href="#">Link</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
        <form class="navbar-form navbar-left">
          <div class="form-group">
            <input type="text" class="form-control" placeholder="Search">
          </div>
          <button type="submit" class="btn btn-default">Submit</button>
        </form>
        <ul class="nav navbar-nav navbar-right">
          <li><a href="#">Link</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a></li>
            </ul>
          </li>
        </ul>
      </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
  </nav>

What I get is just the word "Brand" in blue. I can't see any navbar. I try to add a button above with the class "btn btn-primary" just to see if I have Bootstrap at all. The result is a blue button with white text but it wasn't properly styled like it should (no border for example). It's like bootstrap is only partially working. It is important to emphasize that this code works perfectly on a regular code editor that has the necessary link and script tags.

I downloaded with the CLI bootstrap, jquery and popper.js. I can see them in the node_modules. I also try to see if it works with ngx-bootstrap and without it.

In the file angular.json I wrote:

        "styles": [
          "src/styles.css",
          "node_modules/bootstrap/dist/css/bootstrap.min.css"
        ],
        "scripts": [
          "node_modules/jquery/dist/jquery.min.js",
          "node_modules/popper.js/dist/popper.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.min.js"
        ]   

btw, I don't know if that has anything to do with the problem but unlike all the tutorials I saw the file isn't named angular-cli.json but angular.json, and it doesn't appear in the src folder but outside of it in the main folder. This is why I didn't wrote "../" before "node_modules...".

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
Yarden A
  • 35
  • 2
  • 9
  • You can take a look at [this answer](https://stackoverflow.com/a/49010911/1009922) to see how it can be done with [ng-bootstrap](https://ng-bootstrap.github.io/#/home). – ConnorsFan May 29 '18 at 16:22
  • 1
    You're trying to use Bootstrap 3 markup for Bootstrap 4. See the Bootstrap 4 Navbar Docs: http://getbootstrap.com/docs/4.1/components/navbar/ – Carol Skelly May 29 '18 at 17:21

0 Answers0