[英]ng-bootstrap accordion is not working in for loop in Angular
It does not work in for loop.它在 for 循环中不起作用。
<ng-container *ngFor="let p of [0,1,2]">
<ngb-accordion [closeOthers]="true">
<ngb-panel id={{p}}>
<ng-template ngbPanelTitle>
title
</ng-template>
<ng-template ngbPanelContent>
content
</ng-template>
</ngb-panel>
</ngb-accordion>
</ng-container>
The id should be unique. id 应该是唯一的。 Other panels should close when a new panel is opened.
打开新面板时,其他面板应关闭。 Example: https://ng-bootstrap.github.io/#/components/accordion/examples (One open panel at a time)
示例: https : //ng-bootstrap.github.io/#/components/accordion/examples (一次打开一个面板)
Please find the working code snippet请找到工作代码片段
<ngb-accordion [closeOthers]="true">
<ng-container *ngFor="let result of results; let i= index">
<ngb-panel id="ngb-panel-{{i}}" title="{{result}}">
<ng-template ngbPanelContent>
<div>
hello content{{i}}
</div>
</ng-template>
</ngb-panel>
</ng-container>
</ngb-accordion>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.