Search results

Render other components in Tab using ng-template

You can render other components inside Tab using Angular ng-template. Through this, we can add content as other components directly with all their functionalities to our Tab. We need to use ng-template inside the each e-tabitem tag with #content attribute, which is mandatory to render content. And now use ng-template tag with select attribute of id or class name for mapping required content.

Source
Preview
app.component.ts
app.module.ts
index.css
import { Component, ViewChild } from '@angular/core';
import { enableRipple, createElement } from '@syncfusion/ej2-base';
import { TabComponent, selectEventArgs } from '@syncfusion/ej2-angular-navigations';
import { ComboBoxComponent } from '@syncfusion/ej2-angular-dropdowns';
import { CalenderComponent } from '@syncfusion/ej2-angular-calendars';

enableRipple(true);

@Component({
    selector: 'app-container',
    template: `<ejs-tab id="element">
    <e-tabitems>
        <e-tabitem [header]='headerText[0]'>
            <ng-template #content>

                <ejs-calendar [value]='dateValue' [min]='minDate' [max]='maxDate'></ejs-calendar>

            </ng-template>

        </e-tabitem>
        <e-tabitem [header]='headerText[1]'>

            <ng-template #content>

                <ejs-combobox id='comboelement' #samples [dataSource]='data' [placeholder]='text'></ejs-combobox>

            </ng-template>
        </e-tabitem>
        <e-tabitem [header]='headerText[2]'>
            <ng-template #content>

                <p>text inside tab3</p>

            </ng-template>

        </e-tabitem>
    </e-tabitems>
</ejs-tab>`
})

export class AppComponent {
    @ViewChild('element') tabInstance: TabComponent;

     public headerText: Object = [{ 'text': 'Tab1' }, { 'text': 'Tab2' },{ 'text': 'Tab3' }];
    //calender
    public dateValue: Date = new Date("05/11/2017");
    public minDate: Date = new Date("05/09/2017");
    public maxDate: Date = new Date("05/15/2017");
    // defined the array of data
    public data: string[] = ['Badminton', 'Basketball', 'Cricket', 'Golf', 'Hockey', 'Rugby'];
    // set placeholder text to ComboBox input element
    public text: string = 'Select a game';

}
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';

import { GridAllModule } from '@syncfusion/ej2-angular-grids';
import { DialogAllModule } from '@syncfusion/ej2-angular-popups';
import { TabModule } from '@syncfusion/ej2-angular-navigations';
import { DatePickerAllModule } from '@syncfusion/ej2-angular-calendars';
import { NumericTextBoxAllModule } from '@syncfusion/ej2-angular-inputs';
import { DropDownListAllModule } from '@syncfusion/ej2-angular-dropdowns';

import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        FormsModule,
        TabModule,
        BrowserModule,
        GridAllModule,
        DialogAllModule,
        DatePickerAllModule,
        DropDownListAllModule,
        NumericTextBoxAllModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
#container {
  max-width: 700px;
  min-width: 520px;
}

#loader {
  color: #008cff;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}

.e-content .e-item {
  font-size: 12px;
  margin: 10px;
}