public constructor(
private toasterService: ToasterService) {
}
然后我听烤面包机:
public ngOnInit() {
this.errorWatcher.localConfigObservable.subscribe(exception => {
const toast: any = {
type: exception.type,
body: Helper.toasterBodyMessages(exception.messages)
};
this.toasterService.pop(toast);
});
}
我使用以下方式发送消息:
public invokeMessageOutside(type: string, title: string, message: any) {
this.exception.type = type;
this.exception.title = title;
if (isArray(message)) {
this.exception.messages = message;
} else {
this.exception.messages.push(message);
}
this.call();
}
private call(): void {
this.localConfigObservable.next(this.exception);
}
所以,我不明白为什么有时会显示这个弹出窗口,有时不会。
如果在里面做 console.log() :
this.errorWatcher.localConfigObservable.subscribe(exception => {
console.log('Done');
});
它总是有效的。
我的配置是:
public configToaster: ToasterConfig = new ToasterConfig({
positionClass: "toast-top-right",
showCloseButton: true,
preventDuplicates: true,
timeout: 5000,
tapToDismiss: false,
bodyOutputType: BodyOutputType.TrustedHtml,
mouseoverTimerStop: false
});
也许问题出在:preventDuplicates: true
?