是否可以在Angular 2中单击按钮时关闭所有打开的PrimeNg手风琴选项卡?

时间:2018-01-30 12:56:38

标签: angular primeng

我有PrimeNg手风琴的菜单:

https://www.primefaces.org/primeng/#/accordion

我想按一下按钮关闭那个手风琴。在Angular 2中有可能吗?

1 个答案:

答案 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--;
  }