2
votes

I have used bootstrap style in an Angular 6 project to design the sign up page and it is working fine. But after resizing the browser when I click on the hamburger icon the, it doesn't collapse and hence the icon under the hamburger menu doesn't appear.

Here is the styles tag in angular.json file:

"styles":   [
            "src/styles.css"
            ],

And this is styles.css file:

@import "~bootstrap/dist/css/bootstrap.min.css";
@import '~ngx-toastr/toastr.css';

scripts array in angular.json file:

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

Navbar HTML:

<nav class="navbar navbar-expand-md navbar-dark bg-dark">

  <a class="navbar-brand" href="/">My Chat</a>

  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
    aria-expanded="true" aria-label="Toggle navigation">

    <span class="navbar-toggler-icon"></span>

  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">

    <ul class="navbar-nav">

      <li class="nav-item">

        <a class="nav-link pointer" (click)="goToSignUp()">Sign-Up</a>

      </li>

    </ul>

  </div>

</nav>

<div class="row p-0 m-0">

  <div class="col-sm"></div>

  <div class="col-sm p-5">

    <h2 class="form-signin-heading">Sign in to continue</h2>

    <label for="inputEmail" class="sr-only">Email address</label>

    <input type="email" id="inputEmail" class="form-control" [(ngModel)]="email" placeholder="Email address" required autofocus>

    <br>

    <label for="inputPassword" class="sr-only">Password</label>

    <input type="password" id="inputPassword" class="form-control" [(ngModel)]="password" placeholder="Password" (keydown.enter)="onKeydown()" required>

    <br>

    <button class="btn btn-lg btn-primary btn-block" type="button"  (click)="signInFunction()">Sign in</button>

  </div>

  <div class="col-sm"></div>

</div>

Not sure what I am missing.

2
Post the Navbar HTML too please - Zim
I have posted the navbar html. - Dibash
Probably going to be easier to use ng-bootstrap - medium.com/@frypan/… - James P
Thanks James, but in my application the hamburger menu should only appear when the browser resizes, i.e for mobile or tablet screen. For a desktop view its working fine. - Dibash

2 Answers

1
votes

Try to do this->

  1. npm install -- save @ng-bootstrap/ng-bootstrap

    after ng-bootstrap has completed installation

  2. In app.module.ts-> add -> import { NgbModule} from ‘@ng-bootstrap/ng-bootstrap’; And put it under @NgModule, imports: [NgbModule.forRoot()]

  3. Run your angular app again

Also please try to add "node_modules/bootstrap/dist/css/bootstrap.min.css" under styles in angular.json

And add script imports for jquery, popper and bootstrap available on Bootstrap documentation website inside your project's Index.Html between the HTML body.

0
votes

add script tags before /body in index.html file:

-script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"
  
-script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"