According to Bootstrap 5 (Separate section), Bootstrap 5 requires @popperjs/core but not popperjs. Hence you were installing and importing the wrong library.
FYI, Bootstrap 5 removed dependency on jQuery.
Solution 1: Install @popperjs/core
Pre-requisite: You have installed Bootstrap 5 with
npm install [email protected]
- You are required to install
@popperjs/core
as dependencies. Via npm
npm install @popperjs/core
- Import
@popperjs/core
into angular.json. Popper (library) must come first (if you’re using tooltips or popovers), and then our JavaScript plugins.
angular.json
"scripts": [
"./node_modules/@popperjs/core/dist/umd/popper.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js"
]
Solution 2: Import Bootstrap as bundle
Pre-requisite: You have installed Bootstrap 5 with
npm install [email protected]
Bootstrap bundle includes Popper for our tooltips and popovers. Hence you no need to install @popperjs/core
separately.
- Import the Bootstrap bundle to the angular.json
scripts
array.
angular.json
"scripts": [
"./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
]
Solution 3: Angular Bootstrap
Angular Bootstrap Dropdown is another option that makes Bootstrap works in Angular App.
- Install Angular Bootstrap (NG Bootstrap).
npm install @ng-bootstrap/ng-bootstrap
- Add
NgbModule
into app.module.ts imports section.
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@NgModule({
imports: [.., NgbModule]
})
- Apply Angular Bootstrap Dropdown directive.
<div ngbDropdown class="dropdown">
<button ngbDropdownToggle class="btn btn-secondary" type="button" id="dropdownMenuButton1" aria-expanded="false">
Dropdown button
</button>
<ul ngbDropdownMenu aria-labelledby="dropdownMenuButton1">
<li><a ngbDropdownItem href="#">Action</a></li>
<li><a ngbDropdownItem href="#">Another action</a></li>
<li><a ngbDropdownItem href="#">Something else here</a></li>
</ul>
</div>