Render components in Tab using Angular templates
22 Sep 20254 minutes to read
You can render other components inside Tab using Angular ng-template. This approach enables you to add content as other components directly with all their functionalities integrated into the Tab. The ng-template must be used inside each e-tabitem tag with the #content attribute, which is mandatory to render content. Then use the ng-template tag with a select attribute containing the id or class name for mapping the required content.
Check out this video to learn about integrating other UI components inside the Angular Tab component:
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 { CalendarAllModule } from '@syncfusion/ej2-angular-calendars'
import { NumericTextBoxAllModule } from '@syncfusion/ej2-angular-inputs'
import { ComboBoxAllModule } from '@syncfusion/ej2-angular-dropdowns'
import { Component, ViewChild } from '@angular/core';
import { enableRipple, createElement } from '@syncfusion/ej2-base';
import { TabComponent } from '@syncfusion/ej2-angular-navigations';
import { ComboBoxComponent } from '@syncfusion/ej2-angular-dropdowns';
enableRipple(true);
@Component({
imports: [
FormsModule,
TabModule,
GridAllModule,
DialogAllModule,
CalendarAllModule,
ComboBoxAllModule,
NumericTextBoxAllModule
],
standalone: true,
selector: 'app-container',
template: `<ejs-tab id="element">
<e-tabitems>
<e-tabitem>
<ng-template #headerText>
<div> Tab1 </div>
</ng-template>
<ng-template #content>
<ejs-calendar></ejs-calendar>
</ng-template>
</e-tabitem>
<e-tabitem>
<ng-template #headerText>
<div> Tab2 </div>
</ng-template>
<ng-template #content>
<ejs-combobox id='comboelement' #samples [dataSource]='data' [placeholder]='text'></ejs-combobox>
</ng-template>
</e-tabitem>
<e-tabitem>
<ng-template #headerText>
<div> Tab3 </div>
</ng-template>
<ng-template #content>
<p>text inside tab3</p>
</ng-template>
</e-tabitem>
</e-tabitems>
</ejs-tab>`
})
export class AppComponent {
@ViewChild('element') tabInstance?: TabComponent;
// 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 { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));