Set item wise custom template in Angular Toolbar component
27 Apr 20242 minutes to read
The Toolbar supports adding template commands using the template
property. Template property can be given as the HTML element
that is either a string
or a query selector
.
As string
The HTML element tag can be given as a string for the template property. Here, the checkbox is rendered as a HTML template.
template: "<div><input type='checkbox' id='check1' checked=''>Accept</input></div>"
As selector
The template property also allows getting template content through query selector
. Here, button ‘ID’ attribute is specified in the template.
template: "#Template"
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ToolbarModule } from '@syncfusion/ej2-angular-navigations'
import { TooltipModule } from '@syncfusion/ej2-angular-popups'
import { Component, ViewChild } from '@angular/core';
@Component({
imports: [
ToolbarModule, TooltipModule
],
standalone: true,
selector: 'app-container',
template: `
<button id='Template' class='e-btn'>Template</button>
<ejs-toolbar>
<e-items>
<e-item text='Cut'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Paste' prefixIcon = 'e-paste-icon'></e-item>
<e-item type='Separator'></e-item>
<e-item [template]='templateEle'></e-item>
<e-item text='Undo'></e-item>
<e-item text='Redo'></e-item>
<e-item [template]='templateEleId'></e-item>
</e-items>
</ejs-toolbar>
`
})
export class AppComponent {
@ViewChild('element') element?: any;
public templateEle: any = "<div><input type='checkbox' id='check1' checked=''>Accept</input></div>";
public templateEleId: any = '#Template';
ngAfterViewInit() {
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));