question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ngx-toastr creates and empty 'ng-component' elemnt

See original GitHub issue

When trying to create some toasts, the rendered elements are like the following:

toastr1

I’m trying to use ngx-toaster in a custom component.

Declaring module:

import { NgModule, ModuleWithProviders } from '@angular/core';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';

import { ToastrModule } from 'ngx-toastr';

import { UrlsComponent } from './urls.component';
import { ToastComponent } from './toast.component';

import { AuthService } from './auth/auth.service';
import { AuthInterceptor } from './auth/auth.interceptor';

import { ExchangeService } from './exchange/exchange.service';
import { ExchangeApiService } from './exchange-api/exchange-api.service';

@NgModule({
    imports: [
        HttpClientModule,
        ToastrModule.forRoot({
            toastComponent: ToastComponent // added custom toast!
        })
    ],
    entryComponents: [ToastComponent],
    declarations: [
        UrlsComponent,
        ToastComponent
    ],
    exports: [
        UrlsComponent
    ]
})
export class ApiClientModule {
    static forRoot(): ModuleWithProviders {
        return {
            ngModule: ApiClientModule,
            providers: [
                {
                    provide: HTTP_INTERCEPTORS,
                    useClass: AuthInterceptor,
                    multi: true
                },
                AuthService,
                ExchangeService,
                ExchangeApiService,
                ToastComponent               
            ]
        };
    }
}

And the custom component:

import { Component } from '@angular/core';

import { ToastrService } from 'ngx-toastr';

@Component({
  template: ''
})
export class ToastComponent {

  constructor(private toastr: ToastrService) { }

  addLodingToast() {
    console.log('addLodingToast');
    this.toastr.info('Please wait ...', 'Loading Data', {
      disableTimeOut: true
    });
  }

  addErrorLodingToast() {
    this.addErrorToast('Error', 'Failed to load data.');
  }

  clearAllToasts() {
    this.toastr.clear();
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
scttcpercommented, Aug 11, 2018

You’re both missing BrowserAnimationsModule

0reactions
AminSaqicommented, Aug 13, 2018

You are right. I’ve use it in an interceptor before and had no problem.

OK I’ve got the point. thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ngx-toastr, Toast not showing in Angular 7 - Stack Overflow
I wanted to include ngx-toastr to send notifications to users but it isn't working as expected. When I trigger a toast nothing happens,...
Read more >
ngx-toastr - UNPKG
The CDN for ngx-toastr. ... /toastr.module.ts","ng://ngx-toastr/toastr/toast-noanimation.component.ts"] ... Object.create(b) : (__.prototype = b.prototype, ...
Read more >
ngx-toastr - npm
Start using ngx-toastr in your project by running `npm i ngx-toastr`. ... Toast Component Injection without being passed ViewContainerRef ...
Read more >
ngx-toastr@16.0.1 - jsDocs.io
This method returns the overlay container element. It will lazily create the element the first time it is called to facilitate using the ......
Read more >
Configuring options in Angular Toast component - Syncfusion
Toast can be created with the notification message. The message contains title and content of the Toasts. Title and contents are adaptable in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found