Gathering detailed insights and metrics for toastr-ng2
Gathering detailed insights and metrics for toastr-ng2
Gathering detailed insights and metrics for toastr-ng2
Gathering detailed insights and metrics for toastr-ng2
npm install toastr-ng2
Typescript
Module System
Node Version
NPM Version
TypeScript (52.26%)
HTML (19.21%)
SCSS (14.78%)
CSS (12.84%)
JavaScript (0.92%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2,570 Stars
975 Commits
358 Forks
29 Watchers
4 Branches
53 Contributors
Updated on Jul 16, 2025
Latest Version
4.1.1
Package Id
toastr-ng2@4.1.1
Size
30.74 kB
NPM Version
4.1.2
Node Version
7.4.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
DEMO: https://scttcper.github.io/toastr-ng2/
*ngFor
. Fewer dirty checks and higher performance.1npm install toastr-ng2 --save
step 1: copy toast css to your project. If you are using sass you can import the css.
1@import 'node_modules/toastr-ng2/toastr';
If you are using angular-cli you can add it to your angular-cli.json
"styles": [
"styles.scss",
"node_modules/toastr-ng2/toastr.css"
]
step 2: add ToastrModule to app NgModule
1import { ToastrModule } from 'toastr-ng2'; 2import { CommonModule } from '@angular/common'; 3 4@NgModule({ 5 imports: [ 6 CommonModule, 7 ToastrModule.forRoot(), // ToastrModule added 8 ], 9 bootstrap: [App], 10 declarations: [App], 11}) 12class MainModule {}
Success:
1import { ToastrService } from 'toastr-ng2'; 2@Component({ 3 ... 4}) 5export class YourComponent { 6 constructor(private toastrService: ToastrService) {} 7 8 showSuccess() { 9 this.toastrService.success('Hello world!', 'Toastr fun!'); 10 } 11}
There's global options and individual toast options. All individual toast options are included in the global options. See file toastr-config.ts
The toastComponent can be inherited and modified. See the pink toast in the demo. It has a different animation and inline style.
1maxOpened: number = 0; // max toasts opened. Toasts will be queued 2autoDismiss: boolean = false; // dismiss current toast when max is reached 3iconClasses = { // classes used on toastr service methods 4 error: 'toast-error', 5 info: 'toast-info', 6 success: 'toast-success', 7 warning: 'toast-warning', 8}; 9newestOnTop: boolean = true; // new toast placement 10preventDuplicates: boolean = false; // block duplicate messages
1toastComponent = Toast; // the angular 2 component that will be used 2closeButton: boolean = false; // show close button 3timeOut: number = 5000; // time to live 4enableHtml: boolean = false; // allow html in message. (UNSAFE) 5extendedTimeOut: number = 1000; // time to close after a user hovers over toast 6progressBar: boolean = false; // show progress bar 7toastClass: string = 'toast'; // class on toast 8positionClass: string = 'toast-top-right'; // class on toast 9titleClass: string = 'toast-title'; // class inside toast on title 10messageClass: string = 'toast-message'; // class inside toast on message 11tapToDismiss: boolean = true; // close on click 12onActivateTick: boolean = false; // fire a ApplicationRef.tick() from the toast component when activated. Might help show the toast if you are firing it from a websocket
NEW FOR VERSION > 3 Option 1: Pass values to ToastrModule.forRoot
1// your NgModule 2imports: [ 3 ToastrModule.forRoot({timeOut: 0}), 4],
Option 2: Inject ToastrConfig, typically in your root component, and customize the values.
1import { ToastrConfig } from 'toastr-ng2'; 2import { Component } from '@angular/core'; 3 4@Component({ 5 selector: 'app-root', 6 templateUrl: './app.component.html', 7 styleUrls: ['./app.component.css'] 8}) 9export class AppComponent { 10 constructor(toastrConfig: ToastrConfig) { 11 toastrConfig.timeOut = 100; 12 } 13}
success, error, info, warning take (message, title, ToastConfig)
pass a ToastConfig object to replace several default settings.
1// OPTIONAL: import the ToastConfig interface 2import { ToastConfig } from 'toastr-ng2'; 3 4const errorConfig: ToastConfig = {timeOut: 10000}; 5this.toastrService.error('everything is broken', 'title is optional', errorConfig);
1export interface ActiveToast { 2 toastId: number; // Your Toast ID. Use this to close it individually 3 message: string; // the message of your toast. Stored for prevent duplicate reasons 4 portal?: any; // a reference to the component see portal.ts 5 toastRef?: ToastRef<any>; // a reference to your toast 6 onShown?: Observable<any>; // triggered when toast is active 7 onHidden?: Observable<any>; // triggered when toast is destroyed 8 onTap?: Observable<any>; // triggered on click 9}
Toastr Service will return undefined if prevent duplicates is on.
Put toasts in a specific div inside your application. This should probably be somewhere that doesn't get deleted.
Add ToastContainerModule.forRoot()
to ngModule after the ToastrModule.forRoot()
Add a div with toastContainer
directive on it.
import { ToastContainerDirective } from 'toastr-ng2';
@Component({
selector: 'app-root',
template: `<div toastContainer class="toast-top-right"></div>`,
})
export class AppComponent implements OnInit {
@ViewChild(ToastContainerDirective) toastContainer: ToastContainerDirective;
constructor(private toastrService: ToastrService) {}
ngOnInit() {
this.toastrService.overlayContainer = this.toastContainer;
this.toastrService.success('in div');
}
}
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 toastr-ng2
:
1map: { 2 'toastr-ng2': 'node_modules/toastr-ng2/toastr.umd.js', 3}
angular-toastr and the original toastr.
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
Found 14/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
36 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More