diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 94caa4028a7ef1354ecfeecc0d6c95886b872774..0cce70a2cf83a5d7f8e974aaf2d43438b35ea25e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -44,6 +44,7 @@ import { MatToolbarModule, MatTooltipModule } from '@angular/material'; +import { NotificationService } from './notification.service'; @NgModule({ declarations: [ @@ -90,7 +91,7 @@ import { MatToolbarModule, MatTooltipModule ], - providers: [], + providers: [NotificationService], bootstrap: [AppComponent] }) export class AppModule { diff --git a/src/app/notification.service.spec.ts b/src/app/notification.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..44bc1ec88b688dca88127363d42f9648330471f1 --- /dev/null +++ b/src/app/notification.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { NotificationService } from './notification.service'; + +describe('NotificationService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [NotificationService] + }); + }); + + it('should be created', inject([NotificationService], (service: NotificationService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/notification.service.ts b/src/app/notification.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..ed66238e05c75a7bb9d8dba94addfa3737d294c8 --- /dev/null +++ b/src/app/notification.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@angular/core'; +import { MatSnackBar, MatSnackBarConfig } from '@angular/material'; + +@Injectable() +export class NotificationService { + private defaultConfig = { + duration: 2000 + }; + + constructor(private snackBar: MatSnackBar) { + } + + show(message: string, config?: MatSnackBarConfig) { + // Delegate the message and merge the (optionally) passed config with the default config + this.snackBar.open(message, '', Object.assign({}, this.defaultConfig, config)); + } +}