Clear toasts on navigation events

This commit is contained in:
Adina Țeudan 2020-11-03 12:57:30 +02:00
parent 560c3354d1
commit ca07790597

View File

@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ActiveToast, ToastrService } from 'ngx-toastr';
import { IndividualConfig } from 'ngx-toastr/toastr/toastr-config';
import { NavigationStart, Router } from '@angular/router';
export enum NotificationType {
SUCCESS = 'SUCCESS',
@ -19,7 +20,17 @@ export class Action {
providedIn: 'root'
})
export class NotificationService {
constructor(private readonly _snackBar: MatSnackBar, private readonly _toastr: ToastrService) {}
constructor(
private readonly _snackBar: MatSnackBar,
private readonly _toastr: ToastrService,
private readonly _router: Router
) {
_router.events.subscribe((event) => {
if (event instanceof NavigationStart) {
this._toastr.clear();
}
});
}
showToastNotification(
message: string,