@aminekun90/ngx-toast

中文文档
1.3.0发布于 2026/10/21MITTypeScriptES Module构建来源已验证近 30 天下载 7.8万

A lightweight, high-performance, and Zoneless-ready toast notification library for Angular 20+.

原始使用文档
文档目录17 节
  1. Demo app and usage
  2. Key Features
  3. Installation
  4. Peer Dependencies
  5. Configuration
  6. Usage
  7. 1. Add the Global Container
  8. 2. Triggering Notifications
  9. 3. Global Defaults (optional)
  10. 4. Loading & Promise toasts
  11. Service Methods
  12. Config Reference
  13. Global-only options ( provideToast )
  14. Theming
  15. Compatibility
  16. Keep this project alive :coffee:
  17. Licence

ngx-toast 🍞

A lightweight, high-performance, and Zoneless-ready toast notification library for Angular 20+.

Angular Version Maintenance version number Actions Status License node-current Socket Badge NPM

Demo app and usage

View Demo

Key Features

  • ⚡ Angular 20+ Optimized: Fully supports provideZonelessChangeDetection().
  • 📡 Signal-based: Built with Angular Signals for reactive and efficient state management.
  • 🎨 FontAwesome Integration: Built-in support for professional iconography.
  • 🛠 Customizable: Easy control over duration, progress bars, and screen positions.
  • ♿ Accessible: role="alert", aria-live, keyboard dismissal (Enter/Space/Escape) and focus styles out of the box.
  • ⏸️ Pause on hover: Auto-dismiss timer and progress bar pause while the toast is hovered or focused.
  • 🌙 Theming & dark mode: Restyle everything through CSS variables; automatic prefers-color-scheme support plus an opt-in .ngx-toast-dark class.
  • 🧩 Global defaults: Configure position, duration, max stack, dedup and more via provideToast().
  • 🔁 Promise & loading toasts: First-class loading() and promise() helpers that swap in place.
  • 🪶 Zero runtime deps: No RxJS — purely signal-driven.

Installation

Install the package via Yarn:

yarn add ngx-toast

Peer Dependencies

Since the library uses FontAwesome for its visual components, ensure the following are installed in your project:

yarn add @fortawesome/angular-fontawesome @fortawesome/fontawesome-svg-core @fortawesome/free-solid-svg-icons

Configuration

Add the necessary providers to your app.config.ts (or config.ts). It is highly recommended to use provideAnimationsAsync() for smooth transitions.

import { ApplicationConfig } from '@angular/core';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { fas } from '@fortawesome/free-solid-svg-icons';

export const appConfig: ApplicationConfig = {
  providers: [
    provideAnimationsAsync(),
    {
      provide: 'INITIALIZE_FA',
      useFactory: (library: FaIconLibrary) => library.addIconPacks(fas),
      deps: [FaIconLibrary]
    }
  ]
};

Usage

1. Add the Global Container

Place the ngx-toast-container in your root component (app.ts or app.component.html). This container will handle the stacking and positioning of all active toasts.

import { ToastContainerComponent } from 'ngx-toast';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [ToastContainerComponent],
  template: `
    <router-outlet></router-outlet>
    <ngx-toast></ngx-toast>
  `
})
export class App {}

2. Triggering Notifications


import { Component, inject } from '@angular/core';
import { ToastService } from 'ngx-toast';

@Component({ ... })
export class MyComponent {
  private toastService = inject(ToastService);

  showSuccess() {
    this.toastService.show({
      type: 'success',
      title: 'Success!',
      message: 'The operation was completed successfully.',
      duration: 3000,
      progressBar: true,
      position: 'bottom-right'
    });
  }
}

3. Global Defaults (optional)

Set app-wide defaults with provideToast(). Any value can still be overridden per call.

import { provideToast } from 'ngx-toast';

export const appConfig: ApplicationConfig = {
  providers: [
    provideToast({
      position: 'top-right',
      duration: 4000,
      pauseOnHover: true,
      maxToasts: 5,
      preventDuplicates: true,
      newestOnTop: true,
    }),
  ],
};

4. Loading & Promise toasts

const id = this.toastService.loading('Uploading…');
// later: this.toastService.success('Done!', undefined, { id });

await this.toastService.promise(saveUser(), {
  loading: 'Saving…',
  success: (user) => `Saved ${user.name}`,
  error: (err) => `Failed: ${err}`,
});

Service Methods

MethodReturnsDescription
show(config)numberDisplay a toast; returns its id. Reusing an id updates that toast in place.
success/error/warning/info(message, title?, config?)numberTyped shortcuts.
loading(message, title?, config?)numberPersistent loading toast (no auto-dismiss).
promise(promise, msgs, config?)Promise<T>Shows loading, then swaps to success/error in place.
remove(id)voidDismiss a single toast (with exit animation).
clear(position?)voidDismiss all toasts, optionally filtered by position.
pause(id) / resume(id)voidManually pause/resume the auto-dismiss timer.

Config Reference

PropertyTypeDefaultDescription
type'success' | 'error' | 'warning' | 'info' | 'loading''info'Visual theme and default icon.
titlestringundefinedOptional bold heading above the message.
messagestring—Primary text content.
durationnumber5000ms before auto-close (0 = persistent).
positionToastPosition'bottom-right'One of the six corners/centers.
progressBarbooleanfalseShow a visual countdown bar.
progressAnimation'increasing' | 'decreasing''increasing'Progress bar fill direction.
icon[IconPrefix, IconName]by typeCustom FontAwesome icon.
toastClassstring''Extra CSS class on the toast item.
pauseOnHoverbooleantruePause timer/progress on hover/focus.
themestringundefinedBuilt-in theme (material | glass | minimal | neon | solid) or a custom one.

Global-only options (provideToast)

PropertyDefaultDescription
maxToasts0Max simultaneous toasts (0 = unlimited).
preventDuplicatesfalseRefresh an identical toast instead of stacking.
newestOnTopfalseInsert new toasts at the top of the stack.

Theming

Five built-in themes — material, glass, minimal, neon, solid — applied per toast or globally:

this.toastService.success('Saved!', undefined, { theme: 'glass' });
<!-- or globally on a wrapper -->
<body class="ngx-toast-theme-material">…</body>

Everything is CSS-variable driven, so you can fully restyle or define your own theme. Override tokens anywhere, or toggle dark mode with .ngx-toast-dark:

:root {
  --ngx-toast-radius: 12px;
  --ngx-toast-width: 380px;
  --ngx-toast-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

📖 Full reference: docs/THEMING.md · 🏗️ docs/ARCHITECTURE.md

Compatibility

ngx-toastAngular VersionNode.js VersionChange Detection
1.3.x^21.2.0 | ^22^22.x | ^24.xZoneless & Zone.js
1.2.x^21.2.0 | ^22^22.x | ^24.xZoneless & Zone.js
1.0.x^21.2.0^22.x | ^24.xZoneless & Zone.js

This library is built with Angular 21 and above. Node 24.13.0 or higher is required.

Keep this project alive :coffee:

I dedicate time and effort on writing and maintaining this library and if it helped you and saved you time, please consider Donating!

I'm grateful for your support.

Donate via PayPal

PayPal

Licence

MIT License, By Amine Bouzahar.

版本与发布记录

@aminekun90/ngx-toast 共发布 16 个版本,首次发布于 2026/03/04;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/10/2116 天前
1.2.02026/06/214 个月前
1.1.12026/03/187 个月前
1.1.02026/03/127 个月前
1.0.112026/03/117 个月前
1.0.102026/03/117 个月前

关于 @aminekun90/ngx-toast 的常见问题

@aminekun90/ngx-toast 是什么?

A lightweight, high-performance, and Zoneless-ready toast notification library for Angular 20+.

如何安装 @aminekun90/ngx-toast?

在项目目录运行 npm install @aminekun90/ngx-toast,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/core(^21.2.0 || ^22.0.0)、@angular/common(^21.2.0 || ^22.0.0)、@fortawesome/angular-fontawesome(^4.0.0 || ^5.0.0)、@fortawesome/fontawesome-svg-core(^7.0.0)、@fortawesome/free-solid-svg-icons(^7.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aminekun90/ngx-toast 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aminekun90/ngx-toast 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aminekun90/ngx-toast 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@aminekun90/ngx-toast 可以商用吗?

@aminekun90/ngx-toast 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aminekun90/ngx-toast 的下载量有多少?

根据 npm 官方下载统计,@aminekun90/ngx-toast 在 2026/10/06 – 2026/11/04 这 30 天内被下载 77,588 次,日均约 2,586 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aminekun90/ngx-toast 还在维护吗?

最新版本 1.3.0 发布于 2026/10/21(16 天前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2026/03/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。