Getting started in EJ2 TypeScript Badge control

16 Jun 20232 minutes to read

The following section explains how to create a simple badge component using styles and badge’s basic usage.

Dependencies

Install the following required dependent package to render the Badge component.

|-- @syncfusion/ej2-notifications

Set up your development environment

To get started with a badge component, clone the Essential JS 2 quickstart project, and install the packages by using the following commands.

git clone https://github.com/syncfusion/ej2-quickstart.git quickstart
cd quickstart
npm install

By default, the project is configured with all the Essential JS 2 dependencies. As the badge component is a pure CSS component, do not configure the src/system.config.js file. You can remove that file.

Include badge theme file

The badge CSS files are available in the ej2-notifications package folder. This can be referenced in your application using the following code.

[src/styles/styles.css]

@import '../../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../../node_modules/@syncfusion/ej2-notifications/styles/material.css';

We can also use CRG to generate combined component styles.

Add badge into application

Add an HTML span element with e-badge class inside any wrapper element (h1) into your index.html.

[src/index.html]

<h1>Badge Component <span class="e-badge">New</span></h1>

Run the application

Run the application in the browser using the following command.

npm start

The following example shows a basic badge component.

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 for Badge </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for Badge UI Control" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/23.1.36/ej2-notifications/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'>
            <h1>Badge Component <span class="e-badge e-badge-primary">New</span></h1>
        </div>
    </div>
</body>

</html>

See Also

Types of Badge