Replies: 1 comment 2 replies
-
If you are using Angular, you can utilize Bootstrap's native implementations, e.g., https://coreui.io/angular/docs/components/collapse/ or https://valor-software.com/ngx-bootstrap/components/collapse?tab=overview. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Alright, I'm not filing this under bugs, but I'd really like someone who knows what their doing to tell me why this is not a bug. And I'm going to do something dastardly and include a full chatgpt chat on the subject, including hallucinations, for you to peruse.
The Tl;DR of that is that I am using bootstrap v5.3 with angular v19 and am generally using functionality that takes advantage of data-bs-toggle (Dropdowns, Collapses) all over the site. In one area I want to use the bootstrap JS API to show (not toggle) a particular collapse. Integrating the code to do that into my angular component any which way me or the AI can think of results in either it simply not working, or it breaks all data-bs-toggle functionality all over the page!
I would love someone to tell me how stupid I am. Preferably in a constructive fix the problem way rather than a non-constructive that's what you get for using angular way.
Anyway, feel free to have fun with this one...
Edited by maintainer: hidden the PDF link for security reasons. If OP can copy and paste the content here 🙏
Here is the content pasted from the previous chatgpt pdf transcript as suggested by the maintainer, but due to formatting it is basically unreadable. :-(
Angular Bootstrap Collapse Toggle
Using angular v19 and bootstrap v5.3, I would like to
activate a bootstrap collapse by calling a function in my
angular component. How can I do this?
To programmatically toggle a Bootstrap 5.3 Collapse from an Angular v19 component, you
can use Bootstrap’s JavaScript API ( Collapse class from bootstrap ) in combination with
@ViewChild or document.querySelector .
Here's a step-by-step example:
✅ 1. Install Bootstrap (if not already done)
Then include it in angular.json or your styles/scripts config.
✅ 2. Import Bootstrap Collapse JS (important!)
Angular doesn't automatically include Bootstrap JS, so you must do it manually. Either:
Include it in angular.json :
OR
Dynamically import in your component:
bash
npm install bootstrap
json
"scripts": ["./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"]
ts
import { Collapse } from 'bootstrap';
1/19
✅ 3. Template: Add the collapsible content
✅ 4. Component: Control the Collapse
html
<button (click)="toggleCollapse()">Toggle Collapse
Beta Was this translation helpful? Give feedback.
All reactions