angular observable cache
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(...); }}
Also in JavaScript:
- javascript does key exist
- first name last name concatenate javascript with ternary operator
- how to add google map in react js
- nested for loop javascript
- javascript convert date from mm/dd/yyyy to yyyymmdd
- how to use javascript to get full file path
- how to use fetch() to fetch an image from database in js
- web worker multiple data
- how to get a channelid discord.js
- SyntaxError: Unexpected end of JSON input while parsing near '...version":"2.0.6","devD' cli
- node-fetch auth basic
- array sort by key javascript
- angular input value
- how to add objects in array in javascript
- javascript change meta tag
- ojs link privacy page
- match ids from 2 arrays in javascript asynchronous programming
- how to get a user input in js
- fetch api in js
- reactjs start
- react window navigate
- python object to json
- stopper un intervalle javascript
- javascript includes method