These libraries provide in-app notifications, but their current package metadata and setup target different Angular integrations. Select a compatible host and mounting/provider route before comparing appearance and notification controls.
angular-notifier declares Angular common and core >=16.0.0 and <17.0.0. Its documented setup uses NotifierModule, optional configuration, the notification container and the service. The broad Angular wording in a README is not a replacement for that exact peer range.
ngx-toastr currently declares Angular common/core ^21.0.0 and RxJS ^7.8.2. Its published instructions support ToastrModule.forRoot or provideToastr for the chosen application structure. Follow the current animation and stylesheet route rather than copying every older example unchanged.
angular2-notifications documents SimpleNotificationsModule.forRoot, a simple-notifications host and NotificationsService. Its package has no explicit Angular peer range, which is an unknown constraint rather than evidence that it works on all hosts. Its in-page notifications should not be confused with browser push notifications supplied by a different package.
Map how the application creates, updates, dismisses and identifies messages, where the host is placed and how configuration is inherited. Check timing, stacking, custom templates, keyboard behavior and the app's own error/empty states. A toast reports information; it does not by itself perform the underlying request or make a required user decision.
For an existing application, preserve the supported Angular setup and notification behavior during migration. For a new application, start from the chosen Angular host and the current library requirements. Do not rank these packages as drop-in alternatives while omitting incompatible framework ranges.
Choose it for the ToastrService API with module or standalone provider setup when the host matches its current Angular ^21 and RxJS ^7.8.2 requirements. Include the selected styles.
Choose it when the SimpleNotificationsModule and NotificationsService workflow fits an existing Angular application. Its empty peer declaration does not establish compatibility with every current Angular release.
Choose it for the NotifierModule, service and container API in an application matching its declared Angular range. Its current peers require Angular common/core >=16 and <17.
DEMO: https://ngx-toastr.vercel.app
ViewContainerRef@for. Fewer dirty checks and higher performance@angular/animationsLatest version available for each version of Angular
| ngx-toastr | Angular |
|---|---|
| 13.2.1 | 10.x 11.x |
| 14.3.0 | 12.x 13.x |
| 15.2.2 | 14.x. |
| 16.2.0 | 15.x |
| 17.0.2 | 16.x |
| 18.x 19x | >= 17.x < 23.x |
| current | >= 20.x |
npm install ngx-toastr --save
step 1: add css
// regular style toast
@import 'ngx-toastr/toastr';
// bootstrap style toast
// or import a bootstrap 4 alert styled design (SASS ONLY)
// should be after your bootstrap imports, it uses bs4 variables, mixins, functions
@import 'ngx-toastr/toastr-bs4-alert';
// if you'd like to use it without importing all of bootstrap it requires
@import 'bootstrap/scss/functions';
@import 'bootstrap/scss/variables';
@import 'bootstrap/scss/mixins';
// bootstrap 4
@import 'ngx-toastr/toastr-bs4-alert';
// boostrap 5
@import 'ngx-toastr/toastr-bs5-alert';
"styles": [
"styles.scss",
"node_modules/ngx-toastr/toastr.css" // try adding '../' if you're using angular cli before 6
]
step 2: add ToastrModule to app NgModule, or provideToastr to providers.
import { ToastrModule } from 'ngx-toastr';
@NgModule({
imports: [
ToastrModule.forRoot(), // ToastrModule added
],
bootstrap: [App],
declarations: [App],
})
class MainModule {}
import { AppComponent } from './src/app.component';
import { provideToastr } from 'ngx-toastr';
bootstrapApplication(AppComponent, {
providers: [
provideToastr(), // Toastr providers
]
});
import { ToastrService } from 'ngx-toastr';
import { inject } from '@angular/core';
@Component({...})
export class YourComponent {
toastr = inject(ToastrService);
showSuccess() {
this.toastr.success('Hello world!', 'Toastr fun!');
}
}
There are individual options and global options.
Passed to ToastrService.success/error/warning/info/show()
| Option | Type | Default | Description |
|---|---|---|---|
| toastComponent | Component | Toast | Angular component that will be used |
| closeButton | boolean | false | Show close button |
| timeOut | number | 5000 | Time to live in milliseconds |
| extendedTimeOut | number | 1000 | Time to close after a user hovers over toast |
| disableTimeOut | boolean | 'timeOut' | 'extendedTimeOut' | false | Disable both timeOut and extendedTimeOut when set to true. Allows specifying which timeOut to disable, either: timeOut or extendedTimeOut |
| easing | string | 'ease-in' | Toast component easing |
| easeTime | string | number | 300 | Time spent easing |
| enableHtml | boolean | false | Allow html in message |
| newestOnTop | boolean | true | New toast placement |
| progressBar | boolean | false | Show progress bar |
| progressAnimation | 'decreasing' | 'increasing' | 'decreasing' | Changes the animation of the progress bar. |
| toastClass | string | 'ngx-toastr' | CSS class(es) for toast |
| positionClass | string | 'toast-top-right' | CSS class(es) for toast container |
| titleClass | string | 'toast-title' | CSS class(es) for inside toast on title |
| messageClass | string | 'toast-message' | CSS class(es) for inside toast on message |
| tapToDismiss | boolean | true | Close on click |
| onActivateTick | boolean | false | Fires changeDetectorRef.detectChanges() when activated. Helps show toast from asynchronous events outside of Angular's change detection |
success, error, info, warning take (message, title, ToastConfig) pass an
options object to replace any default option.
this.toastrService.error('everything is broken', 'Major Error', {
timeOut: 3000,
});
All individual options can be overridden in the global options to affect all toasts. In addition, global options include the following options:
| Option | Type | Default | Description |
|---|---|---|---|
| maxOpened | number | 0 | Max toasts opened. Toasts will be queued. 0 is unlimited |
| autoDismiss | boolean | false | Dismiss current toast when max is reached |
| iconClasses | object | see below | Classes used on toastr service methods |
| preventDuplicates | boolean | false | Block duplicate messages |
| countDuplicates | boolean | false | Displays a duplicates counter (preventDuplicates must be true). Toast must have a title and duplicate message |
| resetTimeoutOnDuplicate | boolean | false | Reset toast timeout on duplicate (preventDuplicates must be true) |
| includeTitleDuplicates | boolean | false | Include the title of a toast when checking for duplicates (by default only message is compared) |
iconClasses = {
error: 'toast-error',
info: 'toast-info',
success: 'toast-success',
warning: 'toast-warning',
};
Pass values to ToastrModule.forRoot() or provideToastr() to set global options.
// root app NgModule
imports: [
ToastrModule.forRoot({
timeOut: 10000,
positionClass: 'toast-bottom-right',
preventDuplicates: true,
}),
],
import { AppComponent } from './src/app.component';
import { provideToastr } from 'ngx-toastr';
bootstrapApplication(AppComponent, {
providers: [
provideToastr({
timeOut: 10000,
positionClass: 'toast-bottom-right',
preventDuplicates: true,
}),
]
});
export interface ActiveToast {
/** Your Toast ID. Use this to close it individually */
toastId: number;
/** the title of your toast. Stored to prevent duplicates if includeTitleDuplicates set */
title: string;
/** the message of your toast. Stored to prevent duplicates */
message: string;
/** a reference to the component see portal.ts */
portal: ComponentRef<any>;
/** a reference to your toast */
toastRef: ToastRef<any>;
/** triggered when toast is active */
onShown: Observable<any>;
/** triggered when toast is destroyed */
onHidden: Observable<any>;
/** triggered on toast click */
onTap: Observable<any>;
/** available for your use in custom toast */
onAction: Observable<any>;
}
Put toasts in a specific div inside your application. This should probably be
somewhere that doesn't get deleted. Add ToastContainerDirective to the ngModule
where you need the directive available. Make sure that your container has
an aria-live="polite" attribute, so that any time a toast is injected into
the container it is announced by screen readers.
import { NgModule } from '@angular/core';
import { ToastrModule, ToastContainerDirective } from 'ngx-toastr';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [
ToastrModule.forRoot({ positionClass: 'inline' }),
ToastContainerDirective,
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
Add a div with toastContainer directive on it.
import { Component, OnInit, viewChild, inject } from '@angular/core';
import { ToastContainerDirective, ToastrService } from 'ngx-toastr';
@Component({
selector: 'app-root',
template: `
<h1><a (click)="onClick()">Click</a></h1>
<div aria-live="polite" toastContainer></div>
`,
})
export class AppComponent implements OnInit {
toastContainer = viewChild(ToastContainerDirective, { static: true });
toastrService = inject(ToastrService);
ngOnInit() {
this.toastrService.overlayContainer = this.toastContainer;
}
onClick() {
this.toastrService.success('in div');
}
}
Remove all or a single toast by optional id
toastrService.clear(toastId?: number);
Remove and destroy a single toast by id
toastrService.remove(toastId: number);
If you are using SystemJS, you should also adjust your configuration to point to the UMD bundle.
In your SystemJS config file, map needs to tell the System loader where to
look for ngx-toastr:
map: {
'ngx-toastr': 'node_modules/ngx-toastr/bundles/ngx-toastr.umd.min.js',
}
If you do not want animations you can override the default
toast component in the global config to use
ToastNoAnimation instead of the default one.
In your main module (ex: app.module.ts)
import { ToastrModule, ToastNoAnimation, ToastNoAnimationModule } from 'ngx-toastr';
@NgModule({
imports: [
// ...
ToastNoAnimationModule.forRoot(),
],
// ...
})
class AppModule {}
That's it! No animations.
Create your toast component extending Toast see the demo's pink toast for an example https://github.com/scttcper/ngx-toastr/blob/master/src/app/pink.toast.ts
import { ToastrModule } from 'ngx-toastr';
@NgModule({
imports: [
ToastrModule.forRoot({
toastComponent: YourToastComponent, // added custom toast!
}),
],
bootstrap: [App],
declarations: [App, YourToastComponent], // add!
})
class AppModule {}
ngOnInit() {
setTimeout(() => this.toastr.success('sup'))
}
showToaster() {
this.toastr.success('Hello world!', 'Toastr fun!')
.onTap
.pipe(take(1))
.subscribe(() => this.toasterClickedHandler());
}
toasterClickedHandler() {
console.log('Toastr clicked');
}
toastClass: 'yourclass ngx-toastr'
See: https://github.com/scttcper/ngx-toastr/issues/594.toastr original toastr
angular-toastr AngularJS toastr
notyf notyf (css)
MIT