Add font awesome in Angular Toolbar component

28 Sep 20233 minutes to read

You can customize the Toolbar component items by using third-party icons other than the icons available in the Syncfusion library. In the following example, font awesome icons are used as toolbar items.

  • Refer to the third-party reference link. Here, the CDN link of font awesome is referred.

        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
  • Add the icons to the toolbar component using ‘prefixIcon’ property

The following sample explains how to use font awesome in the toolbar component.

import { Component, ViewChild } from '@angular/core';
import { ToolbarComponent } from '@syncfusion/ej2-angular-navigations';

@Component({
    selector: 'app-container',
    template: `
        <ejs-toolbar>
          <e-items>
          <e-item prefixIcon="fa fa-twitter"></e-item>
          <e-item prefixIcon="fa fa-facebook"></e-item>
          <e-item prefixIcon="fa fa-whatsapp"></e-item>
          <e-item
          template='<button class="e-btn e-tbar-btn"><span><i style="font-size: 3em !important; color: Tomato" class="e-icons fa fa-twitter"></i></span></button>'></e-item>
          </e-items>
       </ejs-toolbar>`
})

export class AppComponent {

}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ToolbarModule } from '@syncfusion/ej2-angular-navigations';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, ToolbarModule
    ],
    declarations: [AppComponent ],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);

We can also use templates for rendering icons based on the requirements.

Customization

The class “e-icons” is used for standardizing the appearance of the icons to fit into toolbar items. If you wish to override the appearance of the icons used, you could do this by using the following set of classes

Use the following CSS to set the color of icons.

    .e-toolbar .e-icons {
        color: #e3165b !important;
    }

Use the following CSS to set the font size of icons.

    .e-toolbar .e-btn .e-icons.e-btn-icon {
        font-size: 14px !important;
    }