Showing
1 changed file
with
10 additions
and
4 deletions
@@ -47,6 +47,8 @@ export class ToastDirective implements AfterViewInit, OnDestroy { | @@ -47,6 +47,8 @@ export class ToastDirective implements AfterViewInit, OnDestroy { | ||
47 | private notificationSubscription: Subscription = null; | 47 | private notificationSubscription: Subscription = null; |
48 | private hideNotificationSubscription: Subscription = null; | 48 | private hideNotificationSubscription: Subscription = null; |
49 | 49 | ||
50 | + private snackBarRef: MatSnackBarRef<TbSnackBarComponent> = null; | ||
51 | + | ||
50 | constructor(public elementRef: ElementRef, | 52 | constructor(public elementRef: ElementRef, |
51 | public viewContainerRef: ViewContainerRef, | 53 | public viewContainerRef: ViewContainerRef, |
52 | private notificationService: NotificationService, | 54 | private notificationService: NotificationService, |
@@ -55,8 +57,6 @@ export class ToastDirective implements AfterViewInit, OnDestroy { | @@ -55,8 +57,6 @@ export class ToastDirective implements AfterViewInit, OnDestroy { | ||
55 | } | 57 | } |
56 | 58 | ||
57 | ngAfterViewInit(): void { | 59 | ngAfterViewInit(): void { |
58 | - const toastComponent = this; | ||
59 | - | ||
60 | this.notificationSubscription = this.notificationService.getNotification().subscribe( | 60 | this.notificationSubscription = this.notificationService.getNotification().subscribe( |
61 | (notificationMessage) => { | 61 | (notificationMessage) => { |
62 | if (notificationMessage && notificationMessage.message) { | 62 | if (notificationMessage && notificationMessage.message) { |
@@ -70,11 +70,17 @@ export class ToastDirective implements AfterViewInit, OnDestroy { | @@ -70,11 +70,17 @@ export class ToastDirective implements AfterViewInit, OnDestroy { | ||
70 | const config: MatSnackBarConfig = { | 70 | const config: MatSnackBarConfig = { |
71 | horizontalPosition: notificationMessage.horizontalPosition || 'left', | 71 | horizontalPosition: notificationMessage.horizontalPosition || 'left', |
72 | verticalPosition: !isGtSm ? 'bottom' : (notificationMessage.verticalPosition || 'top'), | 72 | verticalPosition: !isGtSm ? 'bottom' : (notificationMessage.verticalPosition || 'top'), |
73 | - viewContainerRef: toastComponent.viewContainerRef, | 73 | + viewContainerRef: this.viewContainerRef, |
74 | duration: notificationMessage.duration, | 74 | duration: notificationMessage.duration, |
75 | data | 75 | data |
76 | }; | 76 | }; |
77 | - this.snackBar.openFromComponent(TbSnackBarComponent, config); | 77 | + if (this.snackBarRef) { |
78 | + this.snackBarRef.dismiss(); | ||
79 | + } | ||
80 | + this.snackBarRef = this.snackBar.openFromComponent(TbSnackBarComponent, config); | ||
81 | + this.snackBarRef.afterDismissed().subscribe(() => { | ||
82 | + this.snackBarRef = null; | ||
83 | + }); | ||
78 | } | 84 | } |
79 | } | 85 | } |
80 | } | 86 | } |