Articles in this section
Category / Section

How to get started easily with Syncfusion Angular 11 Badge?

2 mins read

This article explains how to easily get started with the EJ2 Badge component in an Angular 11 project with minimal code. The Essential JS2 Angular Badge component is used to provide alerts to users about new or unread messages, notifications, and additional information related to the content. 


Prerequisites 

Before starting, the following tools and SDKs need to be installed on your machine:


Installation and application creation

  1. You can install Angular CLI 11 using the following command.
npm install -g @angular/cli@11.2.3

 

Note:

If you need to follow and run the application in Angular 9 or earlier version, replace the CLI command version with your preferred version and install it.

 

npm install -g @angular/cli@<CLI VERSION>

 

 

      2. Create an Angular 11 application

ng new angular11-app

cd angular11-app
  1. Installing EJ2 Badge 
npm install @syncfusion/ej2-angular-notifications
  1. Serve the application using the command below. 
ng serve 
  
Your application will open in a browser at http://localhost:4200. Refer to the following screenshot for the Angular 11 version.

Angular-app

 


Adding Angular 11 Badge

 

Since the badge is a CSS component, you just need to import the required CSS style files into the style.css file.

  1. Import the CSS styles of the Badge component.

[style.css]

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

@import '../node_modules/@syncfusion/ej2-angular-notifications/styles/material.css';
  1. Add the Badge component in the template file.

[app.component.html]

<h1>API List type <span class="e-badge e-badge-danger">Deprecated</span></h1>
  1. Run the application using the command, and you can see the following represented output of the EJ2 Angular Badge component. 
ng serve --open

 

badge


Badge styles

 

Badge has the following predefined styles that can be used with the .e-badge class to change the appearance of a badge.

  • e-badge-primary - Represents a primary notification.
  • e-badge-secondary - Represents a secondary notification.
  • e-badge-success - Represents a positive notification.
  • e-badge-danger - Represents a negative notification.
  • e-badge-warning - Represents notification with caution.
  • e-badge-info - Represents an informative notification.
  • e-badge-light - Represents notification in a light variant.
  • e-badge-dark - Represents notification in a dark variant.

[app.component.html]

<h1>Badge type <span class="e-badge e-badge-primary">Primary</span></h1>

<h1>Badge type <span class="e-badge e-badge-secondary">Secondary</span></h1>

<h1>Badge type <span class="e-badge e-badge-success">Success</span></h1>

 

Now, you can see the Badges when you run the application. 

Badge-styles


Notifications

 

The badge style can be applied to notifications by adding the modifier class `.e-badge-notification` to the target element. Notification badges are used when content or a context needs special attention.

When using the notification badge, set the parent element to position: relative.

[app.component.html]

<span style="position: relative;font-size: 22px;">Notification Count

<span class="e-badge e-badge-primary e-badge-notification">99</span>

</span>

 

Now, you can see the changes, as shown below, when you run the application.

Badge-Notification

Conclusion

We hope you enjoyed learning about how to get started easily with Syncfusion Angular 11 Badge.

You can refer to our Angular Badge feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular badge example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied