We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Angular2 Accordion: how to programmatically expand/collapse


i could not find any way to programmatically expand/collapse the panels of the Accordion control at runtime. I am aware of the selectedItems property, but this only seems to set the initial state of the panels, but does not do two-way data-binding at runtime (it is neither updated with the current state of the panels, not does the visible state change when changing the selectedItems property through code)...

Here is what I tried:

  <ej-accordion enableMultipleOpen="true" [(selectedItems)]="selecteditems">
        <a rel='nofollow' href="#">Panel 1</a>
       Panel 1 Text
</div> <h3> <a rel='nofollow' href="#">Panel 2</a> </h3> <div> Panel 2 Text </div> <h3> <a rel='nofollow' href="#">Panel 3</a> </h3> <div> Panel 3 Text </div> </ej-accordion>
<input type="button" ej-button id="button" [value]="Button" (click)="doClick()"/>
And for the Javascript side:

import {Component} from '@angular/core';

     selector: 'sd-home',
     templateUrl: 'app/components/accordion/accordion.component.html'
export class AccordionComponent {
     selecteditems: number[];
       this.selecteditems = [0,1,2];
// collapse all but the first
this.selecteditems = [0]; }
Can you please help here or provide a sample?

Thanks and best regards!

3 Replies

KR Keerthana Rajendran Syncfusion Team June 27, 2017 07:26 AM UTC

Hi Enre,   
Thank you for contacting Syncfusion support.   
We have prepared a sample using your code. Sample works fine and on button click all accordion items are collapsed, only the first item is expanded. We have attached a video for your reference. Please refer the below given link   
We have attached sample for your reference. Kindly refer to the below link    
If the issue persists, kindly modify the above sample to reproduce the issue at our end along with the product version which you are using so that we will analyze and provide better solution at the earliest.   

HE Holger Erne June 29, 2017 04:28 PM UTC

Hi Keerthana,

sorry, everything works - it seems like this simply was a typo in my original sources. The minimized version I presented here to ask the question did not contain this error, so sorry again.

Best regards!

KR Keerthana Rajendran Syncfusion Team June 30, 2017 03:54 AM UTC

Hi Enre,    
Thanks for the update. We are glad to hear that your issue has been resolved. Please get back to us if you require further assistance on this. We will be happy to assist you 

Live Chat Icon For mobile
Up arrow icon