Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular2 toaster - No Toaster Containers have been initialized to receive toasts

i am using angular2-toaster in my angular app

it is very simple,

you define toaster container in the template of component

<toaster-container></toaster-container>

and you use toasterService of type ToasterService to pop op toaster

  this.toasterService.pop('success', 'Args Title', 'Args Body');

but there is a problem with this approach, I would not like to define a container in every component I intend to pop a toaster, I would like to define it once in root component. where application bootstrap but when I do so, I get the error

 No Toaster Containers have been initialized to receive toasts.

any solution?

like image 272
Arash Avatar asked Sep 18 '17 12:09

Arash


1 Answers

Put <toaster-container></toaster-container> in the root component view. Then inject the ToasterService in each of other components. You will still be able to do:

  this.toasterService.pop('success', 'Args Title', 'Args Body');

And don't forget to provide ToastService at module level.

DEMO

like image 113
Vega Avatar answered Oct 18 '22 18:10

Vega