Fix wrong toaster position for error/success, Fixes: #291

This commit is contained in:
ziajka 2019-02-12 13:05:37 +01:00
parent d772a0d9df
commit b00604cc39
2 changed files with 14 additions and 5 deletions

View File

@ -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 }]
});
});

View File

@ -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);
});
}
}