Issue
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);
}
Solution
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(_ =>})
}
Answered By - swordfish
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.