Close All on Page Changes
queejie opened this issue · comments
David Quinn-Jacobs commented
Thanks for this fantastic package. My app pops up info toast message for some pages, and leaves them up for N seconds. However, if the user goes to another page, the message remains displayed. Is there a way to hide all existing messages, or some sort of handle to grab that will allow for closing when changing components?
public postInstructions(message: string, durationMs: number) {
const newToastNotification = new ToastNotificationInitializer();
newToastNotification.setTitle('FYI');
newToastNotification.setMessage(message);
newToastNotification.setConfig({
autoCloseDelay: durationMs,
textPosition: 'left',
layoutType: DialogLayoutDisplay.INFO,
toastUserViewType: ToastUserViewTypeEnum.STANDARD,
animationIn: AppearanceAnimation.SLIDE_IN_DOWN,
animationOut: DisappearanceAnimation.SLIDE_OUT_LEFT,
toastPosition: ToastPositionEnum.TOP_LEFT,
});
newToastNotification.openToastNotification$();
}
David Quinn-Jacobs commented
This solution works, although I'm sure it isn't the best idea:
ngOnDestroy() {
const msgBoxes = document.querySelectorAll('.toast-wrapper');
for (let i = 0; i < msgBoxes.length; i++) {
msgBoxes[i].remove();
}
}
Boris Jeniček commented
sorry, not at the moment.