ng-bootstrap: Problems using accordion inside accordion with Angular 4

I need to use an accordion with other accordions inside. When i was using Angular 2, i worked perfect but when i update to angular 4 using angular-cli 1.0, It stops working.

Here is the code:


<ngb-accordion>
    <ngb-panel title="First panel">
        <template ngbPanelContent>
            <ngb-accordion>
                <ngb-panel id="1" title="First panel">
                    <template ngbPanelContent>
                        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird
                        on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table,
                        raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
                    </template>
                </ngb-panel>
            </ngb-accordion>
        </template>
    </ngb-panel>
</ngb-accordion>

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Try to use ng-template instead of template.

OK, so yesterday I’ve spent some time with Tobias from the Angular team debugging this issue. It turns out that the root cause is a bug in Angular’s handling of queries. I’ve opened an issue to track resolution of Angular’s bug here: https://github.com/angular/angular/issues/16568

Ultimately the solution for this problem will come from https://github.com/angular/angular/issues/16568 but till it is fixed on the Angular side you can use a work-around from http://stackoverflow.com/a/43720470/2435473 (thnx @pankajparkar)

Another solution I found is to wrap the inner accordion in another component, which would essentially do behind the scenes what the previous workaround does.

Pretty much the same thing happens with nested tabs: http://plnkr.co/edit/Gu36tzIlg35DNikjR8kt?p=preview

I updated my project to Angular 4.1.0 and ng-bootstrap 1.0.0-alpha.25. I changed all templates to ng-template but when i tried to use an accordion with another accordion inside again, the issue persisted.

Here is the plunker: https://plnkr.co/edit/JvsDtOIms69iWSHt3l3B?p=preview

As a work-around please keep using <template> for now.