import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs/Observable' ; import { Subject } from 'rxjs/Subject' ; @ Injectable ( ) export class MessageService { private subject = new Subject < any > ( ) ; sendEvent ( event ) { this . subject . next ( event ) ; } subscribeToEvent ( ) { return this . subject . asObservable ( ) ; } }