import { Injectable , Optional , Provider , SkipSelf } from '@angular/core' ; import { Observable } from 'rxjs/Observable' ; import { ReplaySubject } from 'rxjs/ReplaySubject' ; @ Injectable ( ) export class ViewTitleService { private titleSource : ReplaySubject < string > = new ReplaySubject ( 1 ) ; title : Observable < string > = this . titleSource . asObservable ( ) ; set ( title ) { this . titleSource . next ( title ) ; } } export function VIEW_TITLE_SERVICE_PROVIDER_FACTORY ( parentFactory ) { return parentFactory || new ViewTitleService ( ) ; } export const VIEW_TITLE_SERVICE_PROVIDER = { provide : ViewTitleService , useFactory : VIEW_TITLE_SERVICE_PROVIDER_FACTORY , deps : [ [ new Optional ( ) , new SkipSelf ( ) , ViewTitleService ] ] } ;