Search results

Load content through Ajax in Angular Accordion component

20 Apr 2021 / 1 minute to read

Accordion supports to load external contents through AJAX library. Refer the below steps.

  • Import the Ajax module from ej2-base and initialize with URL path.
  • Get data from the Ajax Success event to initialize Accordion with retrieved external path data.
Copied to clipboard
import { Component, ViewChild } from '@angular/core';
import { Ajax } from '@syncfusion/ej2-base';
import { AccordionComponent} from '@syncfusion/ej2-angular-navigations';

selector: 'app-container',
template: `
<div id="acrdnContnet1" style="display:none">
    <ul style="margin : 0px;padding:0px 16px; list-style-type: none">
<div id="acrdnContnet2" style="display:none">
  <ul style="margin : 0px;padding:0px 16px; list-style-type: none">
<ejs-accordion #acrdnInstance>
    <e-accordionitem header='Department' content = '#acrdnContnet1'></e-accordionitem>
    <e-accordionitem header='Platform' content = '#acrdnContnet2'></e-accordionitem>
    <e-accordionitem header='Employee Details'></e-accordionitem>

export class AppComponent {
@ViewChild('acrdnInstance') acrdnInstance: AccordionComponent;
public contentData: string;

ngOnInit() {
let ajax: Ajax = new Ajax('./ajax.html', 'GET', true);
ajax.onSuccess = (data: string): void => {
   this.acrdnInstance.items[2].content = data;
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AccordionModule } from '@syncfusion/ej2-angular-navigations';
import { AppComponent } from './app.component';

 * Module
    imports: [
        BrowserModule, AccordionModule
    declarations: [AppComponent ],
    bootstrap: [AppComponent]
export class AppModule { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

Copied to clipboard
    <div class="comments-list">
        <div class="cont-list">
            <img src="" alt="contact" />
                <div class="time-panel">1 hr</div>
                <b class="headername">Erik Linden</b></div><br><br> London, one of the most popular tourist 
            destinations in the world for a reason. A cultural and historical hub, London has an excellent public 
            transportation system that allows visitors to see all the fantastic sights without spending a ton 
            of money on a rental car. London contains four World Heritage Sites.
            <div class="comments">
                <div class="c-list">Retweet</div>
                <div class="c-list">Reply</div>
                <div class="c-list">Share</div>
    .cont-list img {
        border-radius: 10px;
        float: left;
        height: 56px;
    .comments {
        padding: 10px;
        color: #074B92;
        font-weight: 600;
        position: relative;
        top: 6px;
    .cont-list {        
        padding-bottom: 9px;
    .cont-list:last-child {
        border-bottom: none;
        padding-bottom: 10px;
    .time-panel {
        float: right;
        color: #2382C3;
        margin-right: 10px;
        margin-top: 7px;
    .headername {
        font-size: 16px;
        font-weight: 600;
        color: #074B92;
        position: relative;
        left: 9px;
    .c-list {
        float: right;
        margin-top: -11px;
        padding-right: 12px;