public constructor(
private toasterService: ToasterService) {
}
Then I listen toaster:
public ngOnInit() {
this.errorWatcher.localConfigObservable.subscribe(exception => {
const toast: any = {
type: exception.type,
body: Helper.toasterBodyMessages(exception.messages)
};
this.toasterService.pop(toast);
});
}
I send message using:
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);
}
So, I can not get why sometimes this popup is showed, sometimes no.
If to do console.log() inside:
this.errorWatcher.localConfigObservable.subscribe(exception => {
console.log('Done');
});
It always works.
My config is:
public configToaster: ToasterConfig = new ToasterConfig({
positionClass: "toast-top-right",
showCloseButton: true,
preventDuplicates: true,
timeout: 5000,
tapToDismiss: false,
bodyOutputType: BodyOutputType.TrustedHtml,
mouseoverTimerStop: false
});
Maybe problem is in: preventDuplicates: true
?
Yes.
I created a simple project:
With a service (useless in this case):
And after the first click, I didn't see any other messages. That's because the configuration says: preventDuplicates: true
If you change it to false it will work like a charm.
In case you need this project, you can fork it from here (I don't know why but stackblitz isn't working for any angular project right now): https://stackblitz.com/edit/angular-aiadys
Just remember to do an npm install.