How to add link to Toolbar item in Angular Toolbar
26 Sep 20263 minutes to read
The Angular Toolbar component supports adding interactive links within toolbar items using Angular’s ng-template directive. This approach enables you to embed anchor elements or routing links directly into toolbar items while maintaining full control over their behavior and styling.
Define the ng-template block as a sibling to the <ejs-toolbar> (or in the same template file) with a template reference variable, then reference it from the toolbar item through the [template] input:
<ejs-toolbar>
<e-items>
<e-item [template]="linkRef"></e-item>
</e-items>
</ejs-toolbar>
<ng-template #linkRef>
<a href="https://www.syncfusion.com" target="_blank">Syncfusion</a>
</ng-template>If the link uses
[routerLink], ensureRouterModule(orprovideRouter) is registered in your standalonebootstrapApplication/AppComponentproviders.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ToolbarModule } from '@syncfusion/ej2-angular-navigations'
import { Component } from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-angular-navigations';
@Component({
imports: [
ToolbarModule
],
standalone: true,
selector: 'app-container',
template: `
<ejs-toolbar>
<e-items>
<e-item text='Cut'></e-item>
<e-item text='Copy'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Paste'></e-item>
<e-item type='Separator'></e-item>
<e-item >
<ng-template #template>
<div>
<a
target="_blank"
href="https://ej2.syncfusion.com/angular/documentation/toolbar/getting-started/"
>Anchor Toolbar Link</a
>
</div>
</ng-template>
</e-item>
</e-items>
</ejs-toolbar>
`
})
export class AppComponent {
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));