import { Injectable } from '@angular/core' ; import { CustomEventDetails } from '../interfaces/custom-event-details' ; import { Subject , Subscription } from 'rxjs' ; @ Injectable ( ) export class CustomEventBroadcasterService { private broadcasterSubject = new Subject ( ) ; private broadcasterSubjectAsObservable = this . broadcasterSubject . asObservable ( ) ; constructor ( ) { } subscribeFor ( eventName , callback ) { return this . broadcasterSubjectAsObservable . subscribe ( ( customEvent ) => { if ( customEvent . broadcastEvent === eventName ) { callback ( customEvent . eventDetails ) ; } } ) ; } broadcastEvent ( eventName , eventDetails ? ) { this . broadcasterSubject . next ( { broadcastEvent : eventName , eventDetails : eventDetails } ) ; } }