Getting started with Angular Toolbar component
11 Jul 20247 minutes to read
This section explains briefly about how to create a simple Toolbar using Angular and configuring the Toolbar items like button, separator and input components.
Dependencies
Install the below required dependency package in order to use the Toolbar
component in your application.
|-- @syncfusion/ej2-angular-navigations
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-angular-base
|-- @syncfusion/ej2-navigations
|-- @syncfusion/ej2-buttons
|-- @syncfusion/ej2-popups
Setup Angular Environment
You can use Angular CLI
to setup your Angular applications.
To install Angular CLI use the following command.
npm install -g @angular/cli
Create an Angular Application
Start a new Angular application using below Angular CLI command.
ng new my-app
cd my-app
Installing Syncfusion Toolbar Package
Syncfusion packages are distributed in npm as @syncfusion
scoped packages. You can get all the Angular Syncfusion package from npm link.
Currently, Syncfusion provides two types of package structures for Angular components,
- Ivy library distribution package format
- Angular compatibility compiler(Angular’s legacy compilation and rendering pipeline) package.
Ivy library distribution package
Syncfusion Angular packages(>=20.2.36
) has been moved to the Ivy distribution to support the Angular Ivy rendering engine and the package are compatible with Angular version 12 and above. To download the package use the below command.
Add @syncfusion/ej2-angular-navigations
package to the application.
npm install @syncfusion/ej2-angular-navigations --save
Angular compatibility compiled package(ngcc)
For Angular version below 12, you can use the legacy (ngcc) package of the Syncfusion Angular components. To download the ngcc
package use the below.
Add @syncfusion/ej2-angular-navigations@ngcc
package to the application.
npm install @syncfusion/ej2-angular-navigations@ngcc --save
To mention the ngcc package in the package.json
file, add the suffix -ngcc
with the package version as below.
@syncfusion/ej2-angular-navigations:"20.2.38-ngcc"
Note: If the ngcc tag is not specified while installing the package, the Ivy Library Package will be installed and this package will throw a warning.
Adding CSS reference
The following CSS files are available in ../node_modules/@syncfusion
package folder.
This can be referenced in [src/styles.css] using following code.
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
Add Toolbar component
Modify the template in [src/app/app.component.ts] file to render the toolbar component.
Add the Angular Toolbar by using <ejs-toolbar>
selector in template section of the app.component.ts file.
import { ToolbarModule } from '@syncfusion/ej2-angular-navigations'
import { Component } from '@angular/core';
@Component({
imports: [
ToolbarModule
],
standalone: true,
selector: 'app-root',
// specifies the template string for the Toolbar component
template: `<ejs-toolbar>
<e-items>
<e-item text='Cut'></e-item>
<e-item text='Copy'></e-item>
<e-item text='Paste'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Bold'></e-item>
<e-item text='Italic'></e-item>
<e-item text='Underline'></e-item>
</e-items>
</ejs-toolbar>`
})
export class AppComponent { }
-
Now, run the application in the browser using the following command.
npm start
The following code example depicts the way to initialize The Toolbar on a single element.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ToolbarModule } from '@syncfusion/ej2-angular-navigations'
import { Component, ViewChild } from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-angular-navigations';
@Component({
imports: [
ToolbarModule
],
standalone: true,
selector: 'app-root',
template: `
<ejs-toolbar>
<e-items>
<e-item text='Cut'></e-item>
<e-item text='Copy'></e-item>
<e-item text='Paste'></e-item>
<e-item type='Separator'></e-item>
<e-item text='Bold'></e-item>
<e-item text='Italic'></e-item>
<e-item text='Underline'></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));
Initialize the Toolbar using HTML elements
The Toolbar component can be rendered based on the given HTML element using <ejs-toolbar>
.
You need to follow the below structure of HTML elements to render the Toolbar inside the <ejs-toolbar>
tag.
<ejs-toolbar> --> Root Toolbar Element
<div> --> Toolbar Items Container
<div> --> Toolbar Item Element
</div>
</div>
</ejs-toolbar>
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ToolbarModule } from '@syncfusion/ej2-angular-navigations'
import { Component, ViewChild } from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-angular-navigations';
@Component({
imports: [
ToolbarModule
],
standalone: true,
selector: 'app-root',
template: `
<ejs-toolbar>
<div>
<div><button class='e-btn e-tbar-btn'>Cut</button> </div>
<div><button class='e-btn e-tbar-btn'>Copy</button> </div>
<div><button class='e-btn e-tbar-btn'>Paste</button> </div>
<div class='e-separator'> </div>
<div><button class='e-btn e-tbar-btn'>Bold</button> </div>
<div><button class='e-btn e-tbar-btn'>Italic</button> </div>
</div>
</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));
See Also
NOTE
You can refer to our Angular Toolbar feature tour page for its groundbreaking feature representations. You can also explore our Angular Toolbar Example that shows you how to render the Toolbar in Angular.