答案 0 :(得分:3)
嗯,这是一个简单的方法:
HTML code:
<button type="button" pButton icon="fa fa-chevron-up" (click)="closeAccordion()"></button>
<p-accordion [activeIndex]="index">
<p-accordionTab header="Header 1">
Content 1
</p-accordionTab>
<p-accordionTab header="Header 2">
Content 2
</p-accordionTab>
<p-accordionTab header="Header 3">
Content 3
</p-accordionTab>
</p-accordion>
TS代码:
index: number = null;
lastIndex = -1;
closeAccordion() {
this.index = this.lastIndex--;
}