From b00604cc39efc5211c8f5b5755c30a3606476f30 Mon Sep 17 00:00:00 2001 From: ziajka Date: Tue, 12 Feb 2019 13:05:37 +0100 Subject: [PATCH] Fix wrong toaster position for error/success, Fixes: #291 --- src/app/services/toaster.service.spec.ts | 5 ++++- src/app/services/toaster.service.ts | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/services/toaster.service.spec.ts b/src/app/services/toaster.service.spec.ts index df5edbb7..f88476ed 100644 --- a/src/app/services/toaster.service.spec.ts +++ b/src/app/services/toaster.service.spec.ts @@ -2,6 +2,7 @@ import { TestBed, inject } from '@angular/core/testing'; import { MatSnackBar } from '@angular/material'; import { ToasterService } from './toaster.service'; +import { NgZone } from '@angular/core'; export class MockedToasterService { public errors: string[]; @@ -40,7 +41,9 @@ class MockedSnackBar { describe('ToasterService', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [ToasterService, { provide: MatSnackBar, useClass: MockedSnackBar }] + providers: [ + ToasterService, + { provide: MatSnackBar, useClass: MockedSnackBar }] }); }); diff --git a/src/app/services/toaster.service.ts b/src/app/services/toaster.service.ts index 24d26ae0..0c579428 100644 --- a/src/app/services/toaster.service.ts +++ b/src/app/services/toaster.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, NgZone } from '@angular/core'; import { MatSnackBar } from '@angular/material'; @Injectable() @@ -15,13 +15,19 @@ export class ToasterService { MatSnackBarHorizontalPosition: 'center', MatSnackBarVerticalPosition: 'bottom' }; - constructor(private snackbar: MatSnackBar) {} + constructor( + private snackbar: MatSnackBar, + private zone: NgZone) {} public error(message: string) { - this.snackbar.open(message, 'Close', this.snackBarConfigForError); + this.zone.run(() => { + this.snackbar.open(message, 'Close', this.snackBarConfigForError); + }); } public success(message: string) { - this.snackbar.open(message, 'Close', this.snackBarConfigForSuccess); + this.zone.run(() => { + this.snackbar.open(message, 'Close', this.snackBarConfigForSuccess); + }); } }