Vimal
Vimal

Reputation: 2857

Is it possible to close all the opened PrimeNg accordion tab on a button click in Angular 2?

I have a menu with PrimeNg accordion:

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

and I want to close that accordion on a button click. Is it possible in Angular 2?

Upvotes: 0

Views: 6367

Answers (1)

fabioresner
fabioresner

Reputation: 953

Well, there's an easy way to do it:

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 code:

  index: number = null;
  lastIndex = -1;

  closeAccordion() {
    this.index = this.lastIndex--;
  }

Upvotes: 6

Related Questions