Accordion - activeIndex

UI Components for Angular
Post Reply
lsweb
Posts: 3
Joined: 17 Jun 2022, 09:11

12 Sep 2022, 19:45

Hello,

When I add a new element in an accordion I would like to
- add the new element
- close all tabs
I use the activeIndex property

Here is my code :
- template :

Code: Select all

<p-accordion [multiple]="true" [activeIndex]="activeTab" >
<p-accordionTab *ngFor="let elt of data">
...
</p-accordionTab>
</p-accordion>
- component :

Code: Select all

activeTab = []; // declaration

Code: Select all

onAdd()
 {
    const newElt = ...;
    this.data.unshift(newElt);
    this.activeTab.length = 0; // close all tabs
 }
If the user open tabs before I add and close I obtain the error :
NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.

I probably misuse this component. What is wrong in my code ?

lsweb
Posts: 3
Joined: 17 Jun 2022, 09:11

14 Sep 2022, 15:22

documentation : activeIndex type : any
No very informative. Looking at the examples it seems of type boolean.

So I used 'selected' which works as expected.

I can't make activeIndex work.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests