I've been attempting to create bootstrap accordion items, but unfortunately they're not functioning correctly as shown in the Bootstrap documentation or YouTube tutorials.
In my angular.json file, I have included both bootstrap and jQuery for testing purposes as well as building the application:
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
I have imported bootstrap in my styles.css file:
@import "~bootstrap/dist/css/bootstrap.css";
Both the node_modules and src folders are located within the same app directory.
This is how my HTML file is structured:
<div class="container p-5">
<h1 class="text-center mt-5 mb-5">Angular 12 Bootstrap 5 Accordion with Dynamic Data</h1>
<div class="accordion" id="accordionExample"><!--ngfor loop started for dynamic data -->
<div class="accordion-item" *ngFor="let item of selectedData; let i = index">
<h2 class="accordion-header" [id]="'heading'+i">
<button class="accordion-button" [ngClass]="{ 'collapsed': i != 0 }" type="button" data-bs-toggle="collapse" [attr.data-bs-target]="'#collapse'+i" aria-expanded="true" [attr.aria-controls]="'collapse'+i">
Accordion Item {{i}}
</button>
</h2>
<div [id]="'collapse'+i" class="accordion-collapse collapse" [ngClass]="{ 'show': i == 0 }" [attr.aria-labelledby]="'heading'+i" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
</div>
When I try to interact with the accordions, nothing happens and there seems to be no styling applied.
Here is a screenshot of how it looks when running the app: Click here.
Any suggestions on how to resolve this issue would be greatly appreciated. Thank you.