错误:尚未初始化烤面包机容器以接收烤面包



我在我的 angular 6 应用程序中使用angular2-toaster稍后会使用以下架构将其更新为 9

|___ app.module
|___ shared
|_______shared.module
|_______component
|__________base.component.ts
|___ path
|_______histograme.component

但是我收到此错误No Toaster Containers have been initialized to receive toasts.这是我的直方图.component.ts

import { BaseComponent } from '../../shared/component/base-component';
export class histograme extends BaseComponent implements OnInit, OnDestroy {
...
error => this.showError(..)
}
...

对于我在其中加载了烤面包机模块和服务的基本组件

import { ToasterService, ToasterConfig } from "angular2-toaster";
@Component({
template: 
<toaster-container></toaster-container>
})
export class BaseComponent implements OnDestroy {
protected toasterService: ToasterService;
protected toasterconfig: ToasterConfig = new ToasterConfig({
positionClass: 'toast-top-right',
showCloseButton: true
});
protected ShowError(){
this.toasterService.pop('error', 'Erreur', 'message');
}
}

我的shared.module

imports : [ToasterModule.forRoot()],
providers: [ToasterService],
exports: [ToasterModule]

app.module

imports : [ToasterModule.forRoot()],
providers: [ToasterService],

嗨,在您要显示烤面包机的 html 文件中添加它。

<toaster-container></toaster-container>

private toasterService: ToasterService;
constructor(toasterService: ToasterService) {
this.toasterService = toasterService;
}

最新更新