Giter Club home page Giter Club logo

ngx-toastr's Introduction

Angular Toastr

ngx-toastr


npm codecov

DEMO: https://ngx-toastr.vercel.app

Features

  • Toast Component Injection without being passed ViewContainerRef
  • No use of *ngFor. Fewer dirty checks and higher performance.
  • AoT compilation and lazy loading compatible
  • Component inheritance for custom toasts
  • SystemJS/UMD rollup bundle
  • Animations using Angular's Web Animations API
  • Output toasts to an optional target directive

Dependencies

Latest 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
current >= 17.x

Install

npm install ngx-toastr --save

@angular/animations package is a required dependency for the default toast

npm install @angular/animations --save

Don't want to use @angular/animations? See Setup Without Animations.

Setup

step 1: add css

  • copy toast css to your project.
  • If you are using sass you can import the 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';
  • If you are using angular-cli you can add it to your angular.json
"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, make sure you have BrowserAnimationsModule (or provideAnimations) as well.

  • Module based
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { ToastrModule } from 'ngx-toastr';

@NgModule({
  imports: [
    CommonModule,
    BrowserAnimationsModule, // required animations module
    ToastrModule.forRoot(), // ToastrModule added
  ],
  bootstrap: [App],
  declarations: [App],
})
class MainModule {}
  • Standalone
import { AppComponent } from './src/app.component';
import { provideAnimations } from '@angular/platform-browser/animations';

import { provideToastr } from 'ngx-toastr';

bootstrapApplication(AppComponent, {
  providers: [
    provideAnimations(), // required animations providers
    provideToastr(), // Toastr providers
  ]
});

Use

import { ToastrService } from 'ngx-toastr';

@Component({...})
export class YourComponent {
  constructor(private toastr: ToastrService) {}

  showSuccess() {
    this.toastr.success('Hello world!', 'Toastr fun!');
  }
}

Options

There are individual options and global options.

Individual 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

Setting Individual Options

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,
});

Global Options

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 defaults
iconClasses = {
  error: 'toast-error',
  info: 'toast-info',
  success: 'toast-success',
  warning: 'toast-warning',
};

Setting Global Options

Pass values to ToastrModule.forRoot() or provideToastr() to set global options.

  • Module based
// root app NgModule
imports: [
  ToastrModule.forRoot({
    timeOut: 10000,
    positionClass: 'toast-bottom-right',
    preventDuplicates: true,
  }),
],
  • Standalone
import { AppComponent } from './src/app.component';
import { provideAnimations } from '@angular/platform-browser/animations';

import { provideToastr } from 'ngx-toastr';

bootstrapApplication(AppComponent, {
  providers: [
    provideToastr({
      timeOut: 10000,
      positionClass: 'toast-bottom-right',
      preventDuplicates: true,
    }), 
  ]
});

Toastr Service methods return:

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 your own container

Put toasts in a specific div inside your application. This should probably be somewhere that doesn't get deleted. Add ToastContainerModule 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 { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { ToastrModule, ToastContainerModule } from 'ngx-toastr';

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

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,

    ToastrModule.forRoot({ positionClass: 'inline' }),
    ToastContainerModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

Add a div with toastContainer directive on it.

import { Component, OnInit, ViewChild } 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 {
  @ViewChild(ToastContainerDirective, { static: true })
  toastContainer: ToastContainerDirective;

  constructor(private toastrService: ToastrService) {}
  ngOnInit() {
    this.toastrService.overlayContainer = this.toastContainer;
  }
  onClick() {
    this.toastrService.success('in div');
  }
}

Functions

Clear

Remove all or a single toast by optional id

toastrService.clear(toastId?: number);
Remove

Remove and destroy a single toast by id

toastrService.remove(toastId: number);

SystemJS

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',
}

Setup Without Animations

If you do not want to include @angular/animations in your project 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: [
    // ...

    // BrowserAnimationsModule no longer required
    ToastNoAnimationModule.forRoot(),
  ],
  // ...
})
class AppModule {}

That's it! Animations are no longer required.

Using A Custom Toast

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 {}

FAQ

  1. ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked
    When opening a toast inside an angular lifecycle wrap it in setTimeout
ngOnInit() {
    setTimeout(() => this.toastr.success('sup'))
}
  1. Change default icons (check, warning sign, etc)
    Overwrite the css background-image: https://github.com/scttcper/ngx-toastr/blob/master/src/lib/toastr.css.
  2. How do I use this in an ErrorHandler?
    See: #179.
  3. How can I translate messages?
    See: #201.
  4. How to handle toastr click/tap action?
    showToaster() {
      this.toastr.success('Hello world!', 'Toastr fun!')
        .onTap
        .pipe(take(1))
        .subscribe(() => this.toasterClickedHandler());
    }
    
    toasterClickedHandler() {
      console.log('Toastr clicked');
    }
  5. How to customize styling without overridding defaults?
    Add multiple CSS classes separated by a space:
    toastClass: 'yourclass ngx-toastr'
    See: #594.

Previous Works

toastr original toastr
angular-toastr AngularJS toastr
notyf notyf (css)

License

MIT


GitHub @scttcper Β Β·Β  Twitter @scttcper

ngx-toastr's People

Contributors

bdebon avatar bigwheel avatar chris-allen avatar cmckni3 avatar dimitrijuchtmans avatar eneajaho avatar greenkeeper[bot] avatar greenkeeperio-bot avatar jccint avatar l3ender avatar loetscher avatar peterblazejewicz avatar philippstein avatar ppetkow avatar prashantpimpale93 avatar renovate-bot avatar renovate[bot] avatar rkettelerij avatar scttcper avatar seangwright avatar singatias avatar sylvainpolletvillard avatar timj0212 avatar trevor-hackett avatar tschettler avatar twittwer avatar vglaeser avatar wilt avatar wslaghekke avatar zeldaze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-toastr's Issues

Toaster visible only on next user click

I have an issue, when toaster is supposed to be added by background stream its not being displayed until screen is clicked.
So in order for it to become visible i need to do
setTimeout(_ => { window.document.body.click(); }, 1 );

Is there a better way to run change detection for this component? or maybe i should configure it somehow.

Add Tests

travis and whatever. At least a little bit of coverage.

Error after update package to 2.0.4 version

Hi, after update package error my project :

core.umd.js:2838 EXCEPTION: Error in :0:0 caused by: Expression has changed after it was checked. Previous value: 'CD_INIT_VALUE'. Current value: ''. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?ErrorHandler.handleError @ core.umd.js:2838(anonymous function) @ core.umd.js:6362ZoneDelegate.invoke @ zone.js:232onInvoke @ core.umd.js:5976ZoneDelegate.invoke @ zone.js:231Zone.run @ zone.js:114(anonymous function) @ zone.js:502ZoneDelegate.invokeTask @ zone.js:265onInvokeTask @ core.umd.js:5967ZoneDelegate.invokeTask @ zone.js:264Zone.runTask @ zone.js:154drainMicroTaskQueue @ zone.js:401ZoneTask.invoke @ zone.js:339
core.umd.js:2840 ORIGINAL EXCEPTION: Expression has changed after it was checked. Previous value: 'CD_INIT_VALUE'. Current value: ''. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?ErrorHandler.handleError @ core.umd.js:2840(anonymous function) @ core.umd.js:6362ZoneDelegate.invoke @ zone.js:232onInvoke @ core.umd.js:5976ZoneDelegate.invoke @ zone.js:231Zone.run @ zone.js:114(anonymous function) @ zone.js:502ZoneDelegate.invokeTask @ zone.js:265onInvokeTask @ core.umd.js:5967ZoneDelegate.invokeTask @ zone.js:264Zone.runTask @ zone.js:154drainMicroTaskQueue @ zone.js:401ZoneTask.invoke @ zone.js:339
core.umd.js:2843 ORIGINAL STACKTRACE:ErrorHandler.handleError @ core.umd.js:2843(anonymous function) @ core.umd.js:6362ZoneDelegate.invoke @ zone.js:232onInvoke @ core.umd.js:5976ZoneDelegate.invoke @ zone.js:231Zone.run @ zone.js:114(anonymous function) @ zone.js:502ZoneDelegate.invokeTask @ zone.js:265onInvokeTask @ core.umd.js:5967ZoneDelegate.invokeTask @ zone.js:264Zone.runTask @ zone.js:154drainMicroTaskQueue @ zone.js:401ZoneTask.invoke @ zone.js:339
core.umd.js:2844 Error: Expression has changed after it was checked. Previous value: 'CD_INIT_VALUE'. Current value: ''. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?
    at ExpressionChangedAfterItHasBeenCheckedError.BaseError [as constructor] (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:1105:38)
    at new ExpressionChangedAfterItHasBeenCheckedError (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4649:20)
    at checkBinding (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4758:23)
    at Wrapper_Toast.checkHost (/ToastrModule/Toast/wrapper.ngfactory.js:34:7)
    at CompiledTemplate.proxyViewClass.View_Toast_Host0.detectChangesInternal (/ToastrModule/Toast/host.ngfactory.js:31:19)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:9355:18)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:9448:48)
    at ViewRef_.checkNoChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:7341:70)
    at eval (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:6591:92)
    at Array.forEach (native)ErrorHandler.handleError @ core.umd.js:2844(anonymous function) @ core.umd.js:6362ZoneDelegate.invoke @ zone.js:232onInvoke @ core.umd.js:5976ZoneDelegate.invoke @ zone.js:231Zone.run @ zone.js:114(anonymous function) @ zone.js:502ZoneDelegate.invokeTask @ zone.js:265onInvokeTask @ core.umd.js:5967ZoneDelegate.invokeTask @ zone.js:264Zone.runTask @ zone.js:154drainMicroTaskQueue @ zone.js:401ZoneTask.invoke @ zone.js:339
core.umd.js:2847 ERROR CONTEXT:ErrorHandler.handleError @ core.umd.js:2847(anonymous function) @ core.umd.js:6362ZoneDelegate.invoke @ zone.js:232onInvoke @ core.umd.js:5976ZoneDelegate.invoke @ zone.js:231Zone.run @ zone.js:114(anonymous function) @ zone.js:502ZoneDelegate.invokeTask @ zone.js:265onInvokeTask @ core.umd.js:5967ZoneDelegate.invokeTask @ zone.js:264Zone.runTask @ zone.js:154drainMicroTaskQueue @ zone.js:401ZoneTask.invoke @ zone.js:339
core.umd.js:2848 DebugContext {_view: C…e.proxyViewClass, _nodeIndex: 0, _tplRow: 0, _tplCol: 0}ErrorHandler.handleError @ core.umd.js:2848(anonymous function) @ core.umd.js:6362ZoneDelegate.invoke @ zone.js:232onInvoke @ core.umd.js:5976ZoneDelegate.invoke @ zone.js:231Zone.run @ zone.js:114(anonymous function) @ zone.js:502ZoneDelegate.invokeTask @ zone.js:265onInvokeTask @ core.umd.js:5967ZoneDelegate.invokeTask @ zone.js:264Zone.runTask @ zone.js:154drainMicroTaskQueue @ zone.js:401ZoneTask.invoke @ zone.js:339
zone.js:388 Unhandled Promise rejection: Error in :0:0 caused by: Expression has changed after it was checked. Previous value: 'CD_INIT_VALUE'. Current value: ''. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ? ; Zone: <root> ; Task: Promise.then ; Value: ViewWrappedError {_nativeError: Error: Error in :0:0 caused by: Expression has changed after it was checked. Previous value: 'CD_INI…, originalError: ExpressionChangedAfterItHasBeenCheckedError, context: DebugContext} Error: Expression has changed after it was checked. Previous value: 'CD_INIT_VALUE'. Current value: ''. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?
    at ExpressionChangedAfterItHasBeenCheckedError.BaseError [as constructor] (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:1105:38)
    at new ExpressionChangedAfterItHasBeenCheckedError (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4649:20)
    at checkBinding (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4758:23)
    at Wrapper_Toast.checkHost (/ToastrModule/Toast/wrapper.ngfactory.js:34:7)
    at CompiledTemplate.proxyViewClass.View_Toast_Host0.detectChangesInternal (/ToastrModule/Toast/host.ngfactory.js:31:19)
    at CompiledTemplate.proxyViewClass.AppView.detectChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:9355:18)
    at CompiledTemplate.proxyViewClass.DebugAppView.detectChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:9448:48)
    at ViewRef_.checkNoChanges (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:7341:70)
    at eval (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:6591:92)
    at Array.forEach (native)consoleError @ zone.js:388_loop_1 @ zone.js:417drainMicroTaskQueue @ zone.js:421ZoneTask.invoke @ zone.js:339
zone.js:390 Error: Uncaught (in promise): Error: Error in :0:0 caused by: Expression has changed after it was checked. Previous value: 'CD_INIT_VALUE'. Current value: ''. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?(…)

my Angular versin : 2.2.4

allow html

allow html to be inserted into default toast component when enabled

Default use umd bundle in package.json

In package.json main filed toastr.js is not commonjs compatible, pls use umd or commonjs bundle in main filed and use module field for ES6 build like angular

{
  "main": "./toastr.umd.js",
  "module": "./toastr.js",
  "jsnext:main": "./toastr.js",
  "typings": "./toastr.d.ts",
}

SCSS file in npm package?

Hi,

Currently, if I try to use toastr-ng2 in angular2 project, I need to incorporate the SCSS file manually. Can the file be made part of npm package so that I can just include it out of node_modules?

Thanks for a quick port of toastr!

An in-range update of @angular/core is breaking the build 🚨

Version 2.4.9 of @angular/core just got published.

Branch Build failing 🚨
Dependency @angular/core
Current Version 2.4.8
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/core is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

onTap setup

Can you please tell me how to call a function when click on a toastr?
and if it by using onTap, can you tell me an example.

Thanks in advance.

close html

add closeHtml attribute that will be inserted as a close button

Overriding options based on toast type

Currently options are passed by reference. E.g., if I want to have success toasts time out and error toasts remain, passing options for one will change the other.

Then again, this might be one of those times where I think I know what I'm talking about, but I'm just missing something.

preventDuplicates?

On the demo you can check preventDuplicate, but when i put that option on the config i got the error that is not assignable to the toastr config.
So, is this option avaliable on v1.4.1?

An in-range update of @angular/core is breaking the build 🚨

Version 2.4.10 of @angular/core just got published.

Branch Build failing 🚨
Dependency @angular/core
Current Version 2.4.9
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/core is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Support angular 2.3.0?

Looks like thinks are broken with Angular 2.3.0...

TypeError: this._appRef.registerChangeDetector is not a function
    at DomPortalHost.attachComponentPortal (dom-portal-host.js:41)
    at DomPortalHost.BasePortalHost.attach (portal.js:128)
    at OverlayRef.attach (overlay-ref.js:12)
    at ToastrService._buildNotification (toastr-service.js:111)
    at ToastrService.error (toastr-service.js:21)
...

Need to use attachView now?
http://stackoverflow.com/questions/39857222/angular2-dynamic-component-injection-in-root

Bug with Angular 2.2.0

Simple App

import {Component, NgModule, OnInit, ViewContainerRef, NO_ERRORS_SCHEMA} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {ToastrModule, ToastrService, provideToastr} from 'toastr-ng2';


@Component({
    selector: '.main-app',
    template: '<div>main-app</div>'
})
export class MainApp implements OnInit {
    constructor(
                protected viewContainerRef: ViewContainerRef,
                protected toastr: ToastrService) {

        this.toastr.viewContainerRef = this.viewContainerRef;
    }

    public ngOnInit() {
        setTimeout(() => {
            this.toastr.success('Success');
        }, 2000);
    }
}

@NgModule({
    imports: [
        BrowserModule,
        ToastrModule
    ],
    declarations: [
        MainApp
    ],
    schemas: [
        NO_ERRORS_SCHEMA
    ],
    providers: [
        provideToastr({
            closeButton: true,
            progressBar: true
        })
    ],
    bootstrap: [
        MainApp
    ]
})
export class AppModule {
}

platformBrowserDynamic().bootstrapModule(AppModule);

Throw exception
core.umd.js:2834 EXCEPTION: Error in ./Toast class Toast - inline template:1:10 caused by: Cannot read property 'closeButton' of undefined

"@angular/common": "2.2.0",
"@angular/compiler": "2.2.0",
"@angular/core": "2.2.0",
"@angular/platform-browser": "2.2.0",
"@angular/platform-browser-dynamic": "2.2.0",
"core-js": "^2.4.1",
"es6-promise": "^3.0.2",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.3",
"rxjs": "^5.0.0-rc.3",
"systemjs": "^0.19.27",
"zone.js": "^0.6.21",
"toastr-ng2": "~1.5.6"

With default config (without provideToastr) - same problem

Toast not showing until click on layout when using with ng-bootstrap Modal

Hey there.

I am using a modal from ng-bootstrap: https://ng-bootstrap.github.io/#/components/modal. When I create a toast while the modal is still open but in the process of being closed using this.toastrService.error('Error') this toast does not show up until I click somewhere on the page.
Maybe to explain it better:
The user enters information in the modal and clicks "Save". I do the update in the database, close the modal and want to show a toast "Saved" or "Error".
Semi-pseudo-code:

 updateToDatabase("value").subscribe((value)=>{
     closeModal();
     this.toastrService.success("Wheeeew it worked!");
});

The modal closes, the toast does not show up.
I click somewhere on the page (no matter where exactly) and the toast shows up.
I also tried using
setTimeout(()=>{this.toastrService.success("Wheeew it worked!")},0)

This seems a little odd to me so I figured it's best to just ask.

Thanks for providing the module!

An in-range update of @types/node is breaking the build 🚨

Version 7.0.8 of @types/node just got published.

Branch Build failing 🚨
Dependency @types/node
Current Version 7.0.7
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @types/node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… continuous-integration/travis-ci/push The Travis CI build passed Details

  • βœ… codecov/patch Coverage not affected. Details

  • ❌ codecov/project No report found to compare against Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @types/node is breaking the build 🚨

Version 7.0.6 of @types/node just got published.

Branch Build failing 🚨
Dependency @types/node
Current Version 7.0.5
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @types/node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… continuous-integration/travis-ci/push The Travis CI build passed Details

  • βœ… codecov/patch Coverage not affected. Details

  • ❌ codecov/project No report found to compare against Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

problem with angular cli 1.0.0-beta.24 and angular ^2.3.1 and aot

hi
when i use "ng build --prod --aot " i get this error:
"ERROR in Error encountered resolving symbol values statically. Could not resolve type GlobalToastConfig (position 96:23 in the original .ts file), resolving symbol ToastrConfig in G:/Work/ExamBot/ExamBot/ExamBot/node_modules/toastr-ng2/toastr-config.d.ts"

this happens only with --aot.

i use "toastr-ng2": "3.2.4"
tanx

some auto-dismiss toasts with extended timeout of 0 can just disappear when mouse quickly moves across them

Also, not sure if this is an issue, so I will ask:
When extended timeout is 0 and the progress bar is enabled, if there is a bunch of auto dismiss toasts and you quickly run the mouse across them, some toasts can just disappear instead of what I think should happen, which is just to stop the auto dismiss (stick around).

This is not a huge deal to me but I thought you should know.

Thank you,
Robert

Timeout using extendedTimeout again

There has been a regression in that the extendedTimeout gets used instead of the timeout on all toasts after triggering the extendedTimeout to take effect.

This only happens when the config is set individually and stored in a variable for reuse.

Using version 2.0.1

How to duplicate:

  1. Configure toasts to timeout after desired amount of time (I chose 6000ms)
  2. Configure the extendedTimeout (I chose 1500ms)
  3. Trigger a toast with the configuration
  4. Hover over the toast and mouse away to trigger the extendedTimeout
  5. Trigger another toast without reloading

This causes the next toast to disappear using the extendedTimeout instead of the desired timeout. In my case it disappears in 1500ms instead of 6000ms.

Incorrect timeOut after hover

The initial timeOut works perfectly until you hover over the toast and the extendedTimeOut takes affect. All subsequent toasts use the extendedTimeOut instead of the initial timeOut. This causes the toasts to disappear too quickly.

I have left the config with the defaults. The timeOut was left at 5 seconds and the extendedTimeOut at 1 second. Initially all toasts are displayed for 5 seconds like they should be. Once I hover over the toast (and then away), the extendedTimeOut takes affect and all subsequent toasts disappear after 1 second instead of 5.

toast.success() toast have 2 checkmarks

According to CSS:

#toast-container .toast.toast-success {
    background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR…0CWuABKgnRki9lLseS7g2AlqwHWQSKH4oKLrILpRGhEQCw2LiRUIa4lwAAAABJRU5ErkJggg==) !important;
}

#toast-container > .toast-success:before {
    content: "\F00C";
}

These 2 CSS generate checkmark of their own, which end up showing 2 checkmarks instead of 1 on success(), is there any reason for this?

lodash dependency error

Hi, thanks for great job.
Please add to docs how to "lodash" should be included into project.
I've error like this:

node_modules/toastr-ng2/portal/portal.d.ts(1,1): error TS2688: Cannot find type definition file for 'lodash'.

"toastr-ng2": "^1.4.0",

An in-range update of ts-node is breaking the build 🚨

Version 2.1.2 of ts-node just got published.

Branch Build failing 🚨
Dependency ts-node
Current Version 2.1.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As ts-node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… continuous-integration/travis-ci/push The Travis CI build passed Details

  • βœ… codecov/patch Coverage not affected when comparing 1f59ace...38b2704 Details

  • ❌ codecov/project 73.8% (-0.21%) compared to 1f59ace Details

Release Notes Config Defaults

Fixed

  • Set config defaults after configuration file has been parsed so that they don't override "extended" compiler options (ec00796)
Commits

The new version differs by 3 commits .

  • 4a17778 v2.1.2
  • ec00796 Set default config options after parsing contents
  • b251147 Make tests work under Windows (avoid | in shell)

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of rollup is breaking the build 🚨

Version 0.41.5 of rollup just got published.

Branch Build failing 🚨
Dependency rollup
Current Version 0.41.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As rollup is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… continuous-integration/travis-ci/push The Travis CI build passed Details

  • βœ… codecov/patch Coverage not affected. Details

  • ❌ codecov/project No report found to compare against Details

Commits

The new version differs by 29 commits .

There are 29 commits in total. See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of ts-node is breaking the build 🚨

Version 2.1.1 of ts-node just got published.

Branch Build failing 🚨
Dependency ts-node
Current Version 2.1.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As ts-node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… continuous-integration/travis-ci/push The Travis CI build passed Details

  • ❌ codecov/project 73.8% (-0.21%) compared to 1f59ace Details

  • βœ… codecov/patch Coverage not affected when comparing 1f59ace...a1e4e73 Details

Release Notes Windows Slashes

Fixed

  • Normalize slashes when interacting with TypeScript API
Commits

The new version differs by 4 commits .

  • da704f7 2.1.1
  • 721641e Normalize path slashes for Windows (#285)
  • f9fb954 chore(package): update tsconfig to version 6.0.0 (#290)
  • cf60fd5 chore(package): update tslint-config-standard to version 4.0.0 (#269)

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @types/node is breaking the build 🚨

Version 7.0.10 of @types/node just got published.

Branch Build failing 🚨
Dependency @types/node
Current Version 7.0.9
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @types/node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… continuous-integration/travis-ci/push The Travis CI build passed Details

  • ❌ codecov/project 73.8% (-0.21%) compared to 3ac696c Details

  • βœ… codecov/patch Coverage not affected when comparing 3ac696c...2507670 Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of zone.js is breaking the build 🚨

Version 0.7.8 of zone.js just got published.

Branch Build failing 🚨
Dependency zone.js
Current Version 0.7.7
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As zone.js is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… continuous-integration/travis-ci/push The Travis CI build passed Details

  • ❌ codecov/project No report found to compare against Details

  • βœ… codecov/patch Coverage not affected. Details

Commits

The new version differs by 18 commits (ahead by 18, behind by 2).

  • ce47cfb chore: release v0.7.8
  • 8b2543e fix(webapi): refactor webapi to not import util.ts directly
  • a4c6525 feat(longStackTraceSpec): handled promise rejection can also render longstacktrace (#631)
  • 2d30914 fix(error): fix #618, ZoneAwareError should copy Error's static propeties (#647)
  • 2594940 fix(timers): cleanup task reference when exception (#637)
  • e783bfa feat(bluebird): patch bluebird promise and treat it as microtask (#655)
  • f3b8885 chore: fix formatting
  • 96cb3d0 fix(jasmine): support "pending" it clauses with no test body
  • 36c0899 fix(xhr): fix #657, sometimes xhr will fire onreadystatechange with done twice (#658)
  • 84459f1 fix(package): use fixed version typescript,clang-format and jasmine (#650)
  • fcd8be5 fix(patch): fix #618, use zoneSymbol as property name to avoid name conflict (#645)
  • eb9250d fix(task): fix #638, eventTask/Periodical task should not be reset after cancel in running state (#642)
  • 0534b19 fix(core): remove debugger (#639)
  • 14c7a6f fix(task): findEventTask should return Task array (#633)
  • c07560f fix(zonespec): don't throw and exception when setInterval is called within a async test zone (#641)

There are 18 commits in total. See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @types/node is breaking the build 🚨

Version 7.0.7 of @types/node just got published.

Branch Build failing 🚨
Dependency @types/node
Current Version 7.0.6
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @types/node is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… continuous-integration/travis-ci/push The Travis CI build passed Details

  • βœ… codecov/patch Coverage not affected. Details

  • ❌ codecov/project No report found to compare against Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Output is missing CSS classes

Hello!

Thanks for this ng2 port of Toastr.
Unfortunately, there seems to some kind of problem with the CSS selectors.

An element with id "#toast-container" gets produced, but that element does not contain the actual toast, so the CSS selectors that looks like this:

#toast-container .toast

Doesn't work. The messages just appear on the middle of the screen with full width (only background color is set). If you add the specific types below that selector like this:

#toast-container .toast, .toast-success, .toast-error, .toast-info, .toast-warning { ...

The messages starts to look like they should.
There must be something wrong with the markup and/or missing classes on the output?

Cannot find type definition file for 'lodash' error on following step described in npm site.

I followed all the steps listed in : https://www.npmjs.com/package/toastr-ng2

I am using the fountain.js scaffolding with webpack for my angular 2 project.

I am getting the following typescript error hence my code is not compiling further :

ERROR in /project-root/node_modules/toastr-ng2/portal/portal.d.ts
(1,1): error TS2688: Cannot find type definition file for 'lodash'.

I went ahead and even did npm i lodash, and typings install lodash and
import * as _ from 'lodash'; in my project but nothing helped.

Please help !!

line breaks in message

Hi,
Is there any way currently to put line breaks in the message?
If not, maybe a new option to have the message be trusted HTML.

Not working in aot build

Hi, ngx-toastr seems to stop working in aot build. Toastrs don't show up.

Tested using angular-seed, build.prod.aot.

angular version: ~2.4.0
typescript: ~2.0.9

Anyone else been having this issue?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.