I am trying to cache a request, but in console i get this error where it says:
ERROR Error: Uncaught (in promise): TypeError: observable.pipe is not a function
here is code snippet:
public popularNews: Observable<any>;
// Get popular news
loadPopularNews(params?:any){
let url = `${this.apiUrl}/news/popular`;
let request = this.http.get(url, {params}).pipe(map(data => {})).subscribe(result => {
return result;
});
this.popularNews = this.cache.loadFromObservable(url, request);
}
This one helps a lot.
popularCacheKey = 'popular-news';
// Get popular news
loadPopularNews(params?:any){
let url = `${this.apiUrl}/news/popular`;
let request = this.http.get(url, {params});
this.cache.loadFromObservable(
url,
request,
this.popularCacheKey
).pipe(
map(res =>
this.popularNews = res
)
).subscribe(_ =>})
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.