question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accordion : Work with dynamic CSS class

See original GitHub issue

Bug description:

I want the panels to be clickable but without content.

The idea would be to retrieve the panel that I just click / select in order to pass it in active class and change its color to differentiate it from others.

And of course if I click on another panel, disable / deselect the one that was active before.

So I try to work with dynamic classes in a ngb panel selector but without the [disable] =" true " entry.

When I click on a panel, I print it in the console (example Plunker). Which allows me to identify it.

I tried a lot of things like: [class.active]="true == this.tabSelected.indexOf(item.id) > -1" [ngClass]="'selected'" [class.first-item]="first" [class.last-item]="last" Into following example:

                <!-- Example -->
                <ngb-accordion #acc="ngbAccordion" >
                <!--Dynamic class into this ngb-panel -->
                  <ngb-panel *ngFor=" let child of child.children; let k = index; let first = first; let last = last"  [disabled]="true"  id="test-{{child.id}}" >
                    <ng-template ngbPanelTitle >
                      <div (click)="setClickedRow(j,k)" style="float:left;">
                        {{ child.name }}
                      </div>
                      <button class="btn btn-sm btn-outline-light" style="float:right;">{{ child.price }} €</button>
                    </ng-template>
                    <ng-template ngbPanelContent> 
                    </ng-template>
                  </ngb-panel>
                </ngb-accordion>                  
                <!-- Example  -->

I tried to use [ngClass] = 'selected' in ngb-accordion selector and the css class was changed by “selected”.

But nothing to do at the level of ngb-panel selector, the css class still the same.

I don’t know if it’s possible to do something like that.

You can fork a plunker from one of our demos and use it as a starting point. Please note that we can not act on bug reports without a minimal reproduction scenario in plunker. Here is why: http://plnkr.co/edit/agr9Oe3RN01sn9UeWJ3m?p=preview

Version of Angular, ng-bootstrap, and Bootstrap:

Angular: 5.2.5

ng-bootstrap: 1.0.4

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
IT-CASADOcommented, Apr 17, 2019

I also want to use ngClass or ngStyle for the same reason. Add additional styles on opened tabs…

1reaction
Numalamacommented, Mar 28, 2018

Here is an example of the result I want to optain but with Angular Material: https://stackblitz.com/edit/angular-material2-issue-2262?file=app/app.component.ts

When I click on an item, I change the preselected id list and so the css class became active.

But with ngb how can we make something like that ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

DNN dynamic CSS class for accordion-style container
It works fine as long as the module with this container is only used once per page, but I will need multiple modules...
Read more >
W3.CSS Accordions - W3Schools
An accordion is used to show (and hide) HTML content. Use the w3-hide class to hide the accordion content. Use any kind of...
Read more >
How To Create Dynamic Javascript Accordion [project]
Learn how to build a dynamic Javascript accordion in this tutorial. Play with the project. Download the source code.
Read more >
How to implement a dynamic bootstrap 4 accordion using ...
I'm looking for a way to add a new bootstrap 4 accordion when I click on button. Anybody could you please help me...
Read more >
How to Create Dynamic Bootstrap Accordion - Artisans Web
Accordion (collapsible content) is the best way to toggle(hide and show) large content. The accordion is used to display more data in less ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found