我正在与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: `<div>
<toaster-container [toasterconfig]="config1"></toaster-container>
<button (click)="popToast()">pop toast</button><br/>
</div>`
})
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错误。
发布于 2017-03-05 06:39:35
我也面临着类似的问题。我只是没有在模板中添加烤面包机容器。检查是否在模板中添加了烤面包机组件。
<toaster-container [toasterconfig]="toasterconfig"></toaster-container>更新 安古拉5-烤面包机 5.0.0
现在有了一个5.0.0版本,它允许将烤面包机容器包含在根之外,以及多个容器,同时保证ToasterService的单个实例。这纠正了这种行为
发布于 2017-01-25 01:17:14
我也犯了同样的错误,我这样解决了它:首先,在一个单独的TS中创建组件:
import {NgModule, Component} from '@angular/core';
import {ToasterModule, ToasterService} from 'angular2-toaster';
//import {Root} from './root.component'
@NgModule({
imports: [ToasterModule],
declarations: [toastComponent],
providers: [],
bootstrap: [toastComponent]
})
@Component({
selector: 'root',
template: `
<toaster-container></toaster-container>
<button (click)="popToast()">pop toast</button>`
})
export class toastComponent {
private toasterService: ToasterService;
constructor(toasterService: ToasterService) {
this.toasterService = toasterService;
}
popToast() {
this.toasterService.pop('success', 'Args Title', 'Args Body');
}
}在此之后,导入到您的toastComponent,中,在声明部分-- .module --就这样,您可以在.module中添加标记--记住,这是选择器.module组件.您有一个错误,因为您还没有初始化toastr组件,所以请按照我的步骤执行,并将工作。
https://stackoverflow.com/questions/41692205
复制相似问题