@ngneat/hot-toast vs ngx-toastr
Angular Toast Notifications
@ngneat/hot-toastngx-toastrSimilar Packages:

Angular Toast Notifications

Toast notifications are small, unobtrusive messages that appear on the screen to provide feedback to users. They are commonly used in web applications to display success, error, warning, or informational messages without interrupting the user's workflow. Toast notifications automatically disappear after a short duration, but they can also be configured to remain on the screen until the user interacts with them. This makes them ideal for providing non-intrusive alerts, confirmations, or status updates. @ngneat/hot-toast is a modern, lightweight toast notification library for Angular that offers a simple API, customizable styles, and supports multiple toast types (success, error, info, warning). It is designed for ease of use and minimal configuration, making it suitable for projects that require quick and effective notifications without a large footprint. ngx-toastr is a popular toast notification library for Angular that provides highly customizable and animated toast messages. It supports multiple notification types, allows for manual dismissal, and offers extensive configuration options for positioning, duration, and styling. ngx-toastr is well-suited for applications that need more control over the appearance and behavior of toast notifications, making it a versatile choice for both simple and complex use cases.

Npm Package Weekly Downloads Trend

3 Years

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@ngneat/hot-toast0-401 kB-2 years agoMIT
ngx-toastr02,586175 kB782 months agoMIT

Feature Comparison: @ngneat/hot-toast vs ngx-toastr

Size and Performance

  • @ngneat/hot-toast:

    @ngneat/hot-toast is designed to be lightweight and performant, with a small bundle size that minimizes impact on application load times. Its simplicity and modern implementation ensure fast rendering of toast notifications, making it suitable for performance-sensitive applications.

  • ngx-toastr:

    ngx-toastr is larger than @ngneat/hot-toast due to its extensive feature set and customization options. While it may have a slightly higher impact on load times, it is still performant and suitable for most applications. The trade-off in size is justified by the added flexibility and control it provides over toast notifications.

Customization

  • @ngneat/hot-toast:

    @ngneat/hot-toast offers basic customization options, including the ability to change toast styles, durations, and types (success, error, info, warning). However, it is designed to be simple and may not provide as much depth in customization as ngx-toastr.

  • ngx-toastr:

    ngx-toastr excels in customization, allowing developers to fully control the appearance and behavior of toast notifications. It supports custom templates, animations, positioning, and styling, making it highly versatile for applications that require a tailored notification experience.

API Simplicity

  • @ngneat/hot-toast:

    @ngneat/hot-toast features a simple and intuitive API that makes it easy to create and manage toast notifications with minimal code. Its straightforward design allows developers to quickly integrate it into their applications without a steep learning curve.

  • ngx-toastr:

    ngx-toastr provides a comprehensive API for managing toast notifications, but its complexity may require more time to fully understand and utilize all features. While it is well-documented, the richness of its API can be overwhelming for new users.

Animation and Transitions

  • @ngneat/hot-toast:

    @ngneat/hot-toast includes smooth animations for toast appearance and disappearance, enhancing the user experience without being distracting. The animations are subtle and can be customized to some extent, but they are not as extensive as those offered by ngx-toastr.

  • ngx-toastr:

    ngx-toastr offers highly customizable animations and transitions for toast notifications. Developers can easily configure the entrance and exit animations, as well as the duration and timing, allowing for a more dynamic and engaging notification experience.

Ease of Use: Code Examples

  • @ngneat/hot-toast:

    Basic usage of @ngneat/hot-toast

    import { HotToastModule } from '@ngneat/hot-toast';
    
    @NgModule({
      imports: [HotToastModule]
    })
    export class AppModule {}
    
    // In a component
    import { HotToastService } from '@ngneat/hot-toast';
    
    constructor(private toast: HotToastService) {}
    
    this.toast.success('Success message!');
    this.toast.error('Error message!');
    
  • ngx-toastr:

    Basic usage of ngx-toastr

    import { ToastrModule } from 'ngx-toastr';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    
    @NgModule({
      imports: [
        BrowserAnimationsModule,
        ToastrModule.forRoot() // ToastrModule added
      ]
    })
    export class AppModule {}
    
    // In a component
    import { ToastrService } from 'ngx-toastr';
    
    constructor(private toastr: ToastrService) {}
    
    this.toastr.success('Success message!');
    this.toastr.error('Error message!');
    

How to Choose: @ngneat/hot-toast vs ngx-toastr

  • @ngneat/hot-toast:

    Choose @ngneat/hot-toast if you need a lightweight, easy-to-use toast library with a modern design and minimal configuration. It is ideal for projects that require quick integration and a clean user interface without a lot of overhead.

  • ngx-toastr:

    Choose ngx-toastr if you need a feature-rich toast library with extensive customization options, including animations, positioning, and the ability to create different types of notifications. It is suitable for applications that require more control over the notification appearance and behavior.

README for @ngneat/hot-toast


npm MIT commitizen PRs styled with prettier styled with prettier All Contributors ngneat cypress semantic-release

Smoking hot Notifications for Angular. Lightweight, customizable and beautiful by default. Inspired from react-hot-toast

Compatibility with Angular Versions

@ngneat/hot-toastAngular
3.x >= 9.1.13 < 13
4.x >= 13 < 15
5.x >= 15 < 16
6.x >= 16

Features

  • 🔥 Hot by default
  • Easy to use
  • 🐍 Snackbar variation
  • Accessible
  • 🖐️ Reduce motion support
  • 😊 Emoji Support
  • 🛠 Customizable
  • Observable API
  • Pause on hover
  • 🔁 Events
  • 🔒 Persistent

Installation and setup

You can install it through Angular CLI:

ng add @ngneat/hot-toast

or with npm:

# For Angular version >= 9.1.13 < 13
npm install @ngneat/overview@2.0.2 @ngneat/hot-toast@3

# For Angular version >= 13 < 15
npm install @ngneat/overview@3.0.0 @ngneat/hot-toast@4

# For Angular version >= 15 <16
npm install @ngneat/overview@3.0.0 @ngneat/hot-toast@5

# For Angular version >= 16 <17
npm install @ngneat/overview@5.1.1 @ngneat/hot-toast@6

# For Angular version >= 17
npm install @ngneat/overview@6.0.0 @ngneat/hot-toast@7

Module Setup

This is taken care with ng add @ngneat/hot-toast

Now HotToastModule in your app.module. You can also set global toast options (Partial<ToastConfig>) here.:

import { HotToastModule } from '@ngneat/hot-toast';

@NgModule({
  imports: [HotToastModule.forRoot()],
})
class AppModule {}

Standalone Setup

import { AppComponent } from './src/app.component';

import { provideHotToastConfig } from '@ngneat/hot-toast';

bootstrapApplication(AppComponent, {
  providers: [
    provideHotToastConfig(), // @ngneat/hot-toast providers
  ]
});

Stylings

if you use SCSS add this line to your main styles.scss:

@use '@ngneat/hot-toast/src/styles/styles.scss';

or if you use CSS add this to your styles inside your angular.json:

"styles": [
     "node_modules/@ngneat/hot-toast/src/styles/styles.css",
],

Basic Usage

import { HotToastService } from '@ngneat/hot-toast';

@Component({})
export class AppComponent {
  constructor(private toast: HotToastService) {}

  showToast() {
    this.toast.show('Hello World!');
    this.toast.loading('Lazyyy...');
    this.toast.success('Yeah!!');
    this.toast.warning('Boo!');
    this.toast.error('Oh no!');
    this.toast.info('Something...');
  }

  update() {
    saveSettings
      .pipe(
        this.toast.observe({
          loading: 'Saving...',
          success: 'Settings saved!',
          error: 'Could not save.',
        })
      )
      .subscribe();
  }
}

You can pass ToastOptions while creating the toast to customize the look and behavior:

import { HotToastService } from '@ngneat/hot-toast';

@Component({})
export class AppComponent {
  constructor(private toast: HotToastService) {}

  customToast() {
    this.toast.success('Look at my styles, and I also need more time!', {
      duration: 5000,
      style: {
        border: '1px solid #713200',
        padding: '16px',
        color: '#713200',
      },
      iconTheme: {
        primary: '#713200',
        secondary: '#FFFAEE',
      },
    });
  }
}

You can also set global ToastConfig options while importing:

import { HotToastModule } from '@ngneat/hot-toast';

@NgModule({
  imports: [
    HotToastModule.forRoot({
      reverseOrder: true,
      dismissible: true,
      autoClose: false,
    }),
  ],
})
class AppModule {}

Additionally, you have the option of using a standalone function to provide a global toast configuration within your app's configuration file:

// app.config.ts
import { provideHotToastConfig } from '@ngneat/hot-toast';

export const appConfig: ApplicationConfig = {
  providers: [provideHotToastConfig({ ... })],
};

Examples

You can checkout examples at: https://ngneat.github.io/hot-toast#examples.

ToastConfig

All options, which are set Available in global config? from ToastOptions are supported. Below are extra configurable options:

NameTypeDescription
reverseOrderbooleanSets the reverse order for hot-toast stacking
Default: false
visibleToastsnumberSets the number of toasts visible. 0 will set no limit.
Default: 5
stacking"vertical"|"depth"Sets Sets the type of stacking
Default: "vertical"

ToastOptions

Configuration used when opening an hot-toast.

NameTypeDescriptionAvailable in global config?
idstringUnique id to associate with hot-toast. There can't be multiple hot-toasts opened with same id.
Example
No
durationnumberDuration in milliseconds after which hot-toast will be auto closed. Can be disabled via autoClose: false
Default: 3000, error = 4000, loading = 30000
Yes
autoClosebooleanAuto close hot-toast after duration
Default: true
Yes
positionToastPositionThe position to place the hot-toast.
Default: top-center
Example
Yes
dismissiblebooleanShow close button in hot-toast
Default: false
Example
Yes
roleToastRoleRole of the live region.
Default: status
Yes
ariaLiveToastAriaLivearia-live value for the live region.
Default: polite
Yes
themeToastThemeVisual appearance of hot-toast
Default: toast
Example
Yes
persist{ToastPersistConfig}Useful when you want to keep a persistance for toast based on ids, across sessions.
Example
No
iconContentIcon to show in the hot-toast
Example
Yes
iconThemeIconThemeUse this to change icon color
Example
Yes
classNamestringExtra CSS classes to be added to the hot toast container.Yes
attributesRecord<string, string>Extra attributes to be added to the hot toast container. Can be used for e2e tests.Yes
stylestyle objectExtra styles to apply for hot-toast.
Example
Yes
closeStylestyle objectExtra styles to apply for close buttonYes
dataDataTypeAllows you to pass data for your template and component. You can access the data using toastRef.data.
Examples: Template with Data, Component with Data
No
injectorInjectorAllows you to pass injector for your component.
Example
No

Supported Browsers

Latest versions of Chrome, Edge, Firefox and Safari are supported, with some known issues.

Accessibility

Hot-toast messages are announced via an aria-live region. By default, the polite setting is used. While polite is recommended, this can be customized by setting the ariaLive property of the ToastConfig or ToastOptions.

Focus is not, and should not be, moved to the hot-toast element. Moving the focus would be disruptive to a user in the middle of a workflow. It is recommended that, for any action offered in the hot-toast, the application offers the user an alternative way to perform the action. Alternative interactions are typically keyboard shortcuts or menu options. When the action is performed in this way, the hot-toast should be dismissed.

Hot-toasts that have an action available should be set autoClose: false, as to accommodate screen-reader users that want to navigate to the hot-toast element to activate the action.

Breaking Changes

2.0.2 -> 3.0.0

  • Content inside .hot-toast-message were wrapped into dynamic-content, now they are wrapped into div > dynamic-view
  • Use optional chaining while access toastRef in template. E.g. toastRef?.data
  • Add @Optional() decorator in components' constructor while injecting tokens which are used by toast's injector

4.1.0 -> 5.0.0

For this version you will also need to import the styles from the library like this if you're not using NgAdd

if you use SCSS add this line to your main styles.scss:

@use 'node_modules/@ngneat/hot-toast/src/styles/styles.scss';

or if you use CSS add this to your styles inside your angular.json:

"styles": [
     "node_modules/@ngneat/hot-toast/src/styles/styles.css",
],

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Dharmen Shah
Dharmen Shah

💻 🖋 🎨 📖 💡
Netanel Basal
Netanel Basal

🐛 💼 🤔 🚧 🧑‍🏫 📆 🔬 👀
Timo Lins
Timo Lins

🎨 🤔
Patrick Miller
Patrick Miller

🚧 📦
Gili Yaniv
Gili Yaniv

💻
Artur Androsovych
Artur Androsovych

🚧
Luis Castro
Luis Castro

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Icons made by Freepik from www.flaticon.com