angular observable cache

JavaScript
import { Injectable } from '@angular/core';import { Http, Response } from '@angular/http';import { Observable, ReplaySubject } from 'rxjs';@Injectable()export class CachedService {  data$: Observable<Response> = this.replaySubject.asObservable();  private replaySubject= new ReplaySubject<Response>(1);  constructor(private http: Http) { }  fetch() {    this.http.get(...).subscribe(data =>     this.replaySubject.next(data));  }}@Component({ ... })export class SomeOtherComponent implements OnInit {  constructor(private cachedService: CachedService) { }  ngOnInit() {    this.cachedService.fetch();    this.cachedService.data$.subscribe(...);  }}
Source

Also in JavaScript: