gpt4 book ai didi

angular - 展开 Angular Material Accordion

转载 作者:行者123 更新时间:2023-12-02 00:57:47 27 4
gpt4 key购买 nike

我在同一页有 2 个不同的 Accordion 。每个 Accordion 都有多个扩展面板。如何关闭 2 个 Accordion 的所有扩展面板并打开当前选择的扩展面板?我可以关闭当前 Accordion 的扩展面板,但另一个保持打开状态。两个 Accordion 的作用相同,只是它从不同的列表中获取数据,并且某些 div 位于两个 Accordion 之间

`<mat-accordion [multi]= "true"  >
<mat-expansion-panel *ngFor = "let item of items" (click) = "viewItem(item)" >
<mat-expansion-panel-header>
<mat-panel-title>
//something
</mat-panel-title>
</mat-expansion-panel-header>
//something..
</mat-expansion-panel>
</mat-accordion>
<mat-accordion [multi]= "true" >
<mat-expansion-panel *ngFor = "let item of items" (click) = "viewItem(item)" >
<mat-expansion-panel-header>
<mat-panel-title>
//something
</mat-panel-title>
</mat-expansion-panel-header>
//something..
</mat-expansion-panel>
</mat-accordion>`

最佳答案

当您打开其中一个面板时,您可以关闭所有其他面板:

TS

@ViewChildren(MatExpansionPanel) panels: QueryList<MatExpansionPanel>;

closeOtherPanels(openPanel: MatExpansionPanel) {
this.panels.forEach(panel => {
if (panel !== openPanel) {
panel.close();
}
});
}

HTML
<mat-accordion [multi]= "true">
<mat-expansion-panel *ngFor = "let item of items" (click) = "viewItem(item)" #panel (opened)="closeOtherPanels(panel)" >
<mat-expansion-panel-header>
<mat-panel-title>
//something
</mat-panel-title>
</mat-expansion-panel-header>
//something..
</mat-expansion-panel>
</mat-accordion>
<mat-accordion [multi]= "true">
<mat-expansion-panel *ngFor = "let item of items" (click) = "viewItem(item)" #panel (opened)="closeOtherPanels(panel)" >
<mat-expansion-panel-header>
<mat-panel-title>
//something
</mat-panel-title>
</mat-expansion-panel-header>
//something..
</mat-expansion-panel>
</mat-accordion>

关于angular - 展开 Angular Material Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53089394/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com