0

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],
4

1 回答 1

1

嗨,将此添加到您要显示烤面包机的 html 文件中。

<toaster-container></toaster-container>


   private toasterService: ToasterService;

    constructor(toasterService: ToasterService) {
        this.toasterService = toasterService;
    }
于 2020-06-03T12:27:32.913 回答