I have this code in my app:
public requestList(): Observable<Record[]> {
return this.http.get(this.requestUrl)
.map((response: any) => this.currentList = response.json())
.catch(this.setError);
}
I wish this list was loaded only once from my backend. So I need to check if the currentList
is fulled. If so, I must ignore the http.get()
and manually return currentList
contents to the subscriber, transparently as if he was getting it from the backend. How can I achieve that?
public requestList(): Observable<Record[]> {
if (this.currentList !== undefined) {
// MAGIC HERE: returning content that's already in this.currentList HOW?
}
return this.http.get(this.requestUrl)
.map((response: any) => this.currentList = response.json())
.catch(this.setError);
}