Bind data dynamically - Nested Accordion

How do i bind data dynamically without any  static template in 

I saw this example where there is static content, but i want to get data from API and set the data accordingly to accordian items
<ejs-accordion #element (expanding)="expanding($event)">
        <e-accordionitems>
          <e-accordionitem expanded='true'>
            <ng-template #header>
              <div>Video</div>
            </ng-template>
            <ng-template #content>
              <div id="nested_video"></div>
            </ng-template>
          </e-accordionitem>
          <e-accordionitem>
            <ng-template #header>
              <div>Music</div>
            </ng-template>
            <ng-template #content>
             <div id="nested_music"></div>
            </ng-template>
          </e-accordionitem>
          <e-accordionitem>
            <ng-template #header>
              <div>Images</div>
            </ng-template>
            <ng-template #content>
             <div id="nested_images"></div>
            </ng-template>
          </e-accordionitem>
        </e-accordionitems>
    </ejs-accordion>

1 Reply

BS Balasubramanian Sattanathan Syncfusion Team April 30, 2020 02:21 PM UTC

Hi vin, 

Greetings from Syncfusion Support. 

We have validated your requirement “Bind data dynamically - Nested Accordion” at our side and prepared a sample based on that using the below code snippet. In the below sample, initially the accordion items are added from the service API and the nested accordion will be added dynamically when we add the CLICK TO ADD ITEM button 

public click() { 
  let items = { 
    header: 'Nested Accordion', content: '#element2' 
  }; 
  this.itemsData.push(items); 
  this.accordionObj.items = this.itemsData; 
  this.accordionObj.dataBind(); 
} 


Kindly try the above links and let us know if you need further assistance. 

Regards, 
Balasubramanian S

Loader.
Up arrow icon