我在angular2应用程序中使用angular2烤面包机.在应用程序启动时,我得到以下错误.
我的app_module如下:
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { HttpModule } from '@angular/http'; import { ReactiveFormsModule } from '@angular/forms'; import { ToasterModule, ToasterService} from 'angular2-toaster'; import { AppComponent } from './app.component'; @NgModule({ imports: [ BrowserModule, FormsModule, AppRoutingModule, HttpModule, ToasterModule ], declarations: [AppComponent, HomeComponent, CategoryListComponent, ConsultSotiComponent, HeaderComponent, FooterComponent], providers: [CategoryListService, LeadService, LookUpDetailsService, CompanyService, ConsultSotiService, ToasterService], bootstrap: [AppComponent] }) export class AppModule { }
我也引导了这个模块.
我的app.component如下:
import { Component } from '@angular/core'; import { OnInit } from '@angular/core'; import { TranslateService } from './translate/translate.service'; import { ToasterService} from 'angular2-toaster'; @Component({ selector: 'mp-app', providers: [ToasterService], template: `` }) export class AppComponent implements OnInit { title = 'Enterprise MarketPlace'; public translatedText: string; public supportedLanguages: any[]; constructor(private _translate: TranslateService, private toasterService: ToasterService) { this.popToast(); } popToast() { this.toasterService.pop('success', 'Args Title', 'Args Body'); }
这会导致No Toaster Containers have been initialized to receive toasts
错误.
我遇到了类似的问题.我只是没有在模板中添加烤箱容器.检查您是否在模板中正确添加了烤面包机组件.
更新Angular5-Toaster 5.0.0
现在有一个5.0.0版本,它允许在根目录外部包含多士炉容器,以及多个容器,同时保证ToasterService的单例.这可以纠正这种行为