我angular2-toaster
在我的 Angular 6 应用程序中使用将在稍后使用此模式将其更新为 9:
|___ app.module
|___ shared
|_______shared.module
|_______component
|__________base.component.ts
|___ path
|_______histograme.component
但我收到这个错误No Toaster Containers have been initialized to receive toasts.
是我的 histograme.component.ts
import { BaseComponent } from '../../shared/component/base-component';
export class histograme extends BaseComponent implements OnInit, OnDestroy {
...
error => this.showError(..)
}
...
对于我加载 ToasterModule 和 Service 的 baseComponent
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]
应用程序模块
imports : [ToasterModule.forRoot()],
providers: [ToasterService],