Icons in Angular Floating action button component

20 Dec 20223 minutes to read

You can customize the icon and text of Angular Floating Action Button(FAB) using iconCss and content properties.

FAB with icon

You can show icon only in Floating Action Button by setting iconCss property. You can show tooltip on hover to show additional details to end-user by setting title attribute.

import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: ` <!-- To Render Floating Action Button with icon only -->
                <button ejs-fab id='fab' iconCss= 'fab-icons fab-icon-people'></button>`
})

export class AppComponent { }

FAB with icon and text

You can show icon along with text in Floating Action Button by setting iconCss and content properties.

import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<!-- To Render Floating Action Button with icon and text -->
                <button ejs-fab id='fab' iconCss= 'fab-icons fab-icon-people' content= 'Contacts'></button>`
})

export class AppComponent { }

Icon position

You can change the position of icon when showing along with content by setting iconPosition property. By default, the icon is positioned on the left side together with text.

import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<!-- To Render Floating Action Button with icon position -->
                <button ejs-fab id='fab' iconCss= 'fab-icons fab-icon-people' content= 'Contacts' iconPosition= 'Right'></button>`
})

export class AppComponent { }

Below example demonstrates a FAB with icon and text.

import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<div id="targetElement" style="position:relative;min-height:350px;border:1px solid;">
               </div>
               <!-- To Render Floating Action Button -->
                <button ejs-fab id='fab' iconCss= 'fab-icons fab-icon-people' content= 'Contacts' iconPosition= 'Right' target= '#targetElement'></button>`
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { FabModule } from '@syncfusion/ej2-angular-buttons'

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

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);