简体   繁体   English

离子:observable.pipe 不是一个函数

[英]Ionic: observable.pipe is not a function

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(_ =>})
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM