Having trouble getting help?
Contact Support
Contact Support
Item template in Angular Drop down button component
15 Dec 20242 minutes to read
The itemTemplate property in the DropDownButton component allows for the definition of custom templates to display dropdown items. This feature is especially useful for customizing the appearance and layout of dropdown items beyond the default options provided. By utilizing this property, diverse content such as icons, formatted text, and other visual elements can be integrated into the dropdown items for a more engaging and tailored user interface.
import { Component } from '@angular/core';
import { DropDownButtonModule, ItemModel } from '@syncfusion/ej2-angular-splitbuttons';
import { CommonModule } from '@angular/common';
@Component({
standalone: true,
selector: 'app-root',
template: `
<div class="e-section-control">
<!-- DropDownButton with custom itemTemplate -->
<button ejs-dropdownbutton [items]='items' content='DropdownButton' [itemTemplate]='itemTemplate'></button>
<ng-template #itemTemplate let-data>
<div>
<span class="e-menu-icon "></span>
<ng-container *ngIf="data.url; else textTemplate">
<span class="custom-class"><a [href]="data.url" target="_blank" rel="noopener noreferrer"></a></span>
</ng-container>
<ng-template #textTemplate>
<span class="custom-class"></span>
</ng-template>
</div>
</ng-template>
</div>
`,
imports: [DropDownButtonModule, CommonModule]
})
export class AppComponent {
// Initialize DropDownButton items
public items: ItemModel[] = [
{ text: 'Home', iconCss: 'e-icons e-home' },
{ text: 'Search', iconCss: 'e-icons e-search', url: 'http://www.google.com' },
{ text: 'Yes / No', iconCss: 'e-icons e-check-box' },
{ text: 'Text', iconCss: 'e-icons e-caption' },
{ separator: true },
{ text: 'Syncfusion', iconCss: 'e-icons e-mouse-pointer', url: 'http://www.syncfusion.com' }
];
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));