Badge customization in Angular Badge component

27 Sep 20238 minutes to read

Colour customization

Even though badges come with 8 predefined colors, you can also customize the colour of the badge as desired.

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

@Component({
    selector: 'my-app',
    template: `
    <div id='element'>
            <h1>Color Customization <span class="e-badge e-badge-primary e-badge-pill green">New</span></h1>
            <h1>Color Customization <span class="e-badge e-badge-primary e-badge-pill blue">New</span></h1>
            <h1>Color Customization <span class="e-badge e-badge-primary e-badge-pill purple">New</span></h1>
            <h1>Color Customization <span class="e-badge e-badge-primary e-badge-pill gradient">New</span></h1>
    </div>
    `
})

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

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
    ],
    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);

Customize badge size

Badges are designed to change its size based on the content. To change the size of a badge,
adjust the font size of the badge.

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

@Component({
    selector: 'my-app',
    template: `
    <div id='element'>
            <h1>Badge Component <span class="e-badge e-badge-primary size_1">New</span></h1>
            <h1>Badge Component <span class="e-badge e-badge-primary size_2">New</span></h1>
            <h1>Badge Component <span class="e-badge e-badge-primary size_3">New</span></h1>
    </div>
    `
})

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

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
    ],
    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);

Custom position

Even though the badges support the conventional top and bottom positions, the position of the badges can be changed as desired.
This can be done by adding a custom class to the badge element to override the default position applied from the source.

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

@Component({
    selector: 'my-app',
    template: `
    <div id='element'>
            <div style="width: 200px;margin: 10px auto;">
                <div class="badge-block">
                    <div class="whatsapp svg_icons"></div>
                    <!-- Warning Colored Notification Badge -->
                    <span class="e-badge e-badge-warning e-badge-notification e-badge-overlap leftTop">99+</span>
                </div>

                <div class="badge-block">
                    <div class="facebook svg_icons"></div>
                    <!-- Danger Colored Notification Badge -->
                    <span class="e-badge e-badge-danger e-badge-notification e-badge-overlap leftTop">99+</span>
                </div>

                <div class="badge-block">
                    <div class="skype svg_icons"></div>
                    <!-- Secondary Colored Notification Badge -->
                    <span class="e-badge e-badge-secondary e-badge-notification e-badge-overlap leftTop">18</span>
                </div>
            </div>
            <div style="width: 200px;margin: 10px auto;">
                <div class="badge-block">
                    <div class="whatsapp svg_icons"></div>
                    <!-- Warning Colored Notification Badge -->
                    <span class="e-badge e-badge-warning e-badge-notification e-badge-overlap leftBottom">99+</span>
                </div>

                <div class="badge-block">
                    <div class="facebook svg_icons"></div>
                    <!-- Danger Colored Notification Badge -->
                    <span class="e-badge e-badge-danger e-badge-notification e-badge-overlap leftBottom">99+</span>
                </div>

                <div class="badge-block">
                    <div class="skype svg_icons"></div>
                    <!-- Secondary Colored Notification Badge -->
                    <span class="e-badge e-badge-secondary e-badge-notification e-badge-overlap leftBottom">18</span>
                </div>
            </div>
        </div>
    `
})

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

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
    ],
    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);