Currently, I'm utilizing Bootstrap 4 and Ng-Bootstrap within an Angular 4 Project.
I've included the bootstrap.css in my angular-cli.json as follows:
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.css",
"styles.css"
],
In addition, I have imported the NgbModule in my app.module structured like this:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
NgbModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
I've constructed a Navbar by emulating the instructions from the Bootstrap website and integrated the toggle component from ng-bootstrap (which is functional). The code snippet appears below:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" 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>
<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>
<div ngbDropdown class="d-inline-block">
<div class="nav-link" id="dropdownBasic1" ngbDropdownToggle>Toggle
dropdown</div>
<div ngbDropdownMenu aria-labelledby="dropdownBasic1">
<button class="dropdown-item">Action - 1</button>
<button class="dropdown-item">Another Action</button>
<button class="dropdown-item">Something else is here</button>
</div>
</div>
</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="search" placeholder="Search"
aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0"
type="submit">Search</button>
</form>
</div>
</nav>
The issue arises when I resize the window and trigger the collapse function of the navbar; it doesn't respond as expected.
I attempted to install and link the JavaScript files for jquery, popper, and bootstrap, but unfortunately, it still isn't functioning correctly. Below is how the current angular-cli.json file appears:
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.css",
"styles.css"
],
"scripts": [
"../node_modules/popper.js/dist/umd/popper.min.js",
"../node_modules/jquery/jquery.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
],
What could be causing this problem?