import { filter } from 'rxjs/operators' ; import { Injectable } from '@angular/core' ; import { BehaviorSubject , Observable } from 'rxjs' ; import { Notification } from './notification.model' ; @ Injectable ( ) export class NotificationsService { private subject = new BehaviorSubject < Notification > ( null ) ; constructor ( ) { } public getNotification ( id ? ) { return this . subject . asObservable ( ) . pipe ( filter ( ( x ) => { return x && x . id === id ; } ) ) ; } public success ( message ) { this . notification ( new Notification ( { message , type : 'success' } ) ) ; } public error ( message ) { this . notification ( new Notification ( { message , type : 'error' } ) ) ; } public info ( message ) { this . notification ( new Notification ( { message , type : 'info' } ) ) ; } public warn ( message ) { this . notification ( new Notification ( { message , type : 'warning' } ) ) ; } private notification ( alert ) { this . subject . next ( alert ) ; } private clear ( id ? ) { this . subject . next ( new Notification ( { id } ) ) ; } }