2016-11-21 58 views
2

我正在尝试以获取滚动文本上的数据,并填充一个“Article []”的数组。

httpLoadArticles() { 
    this.httpWSGetInit().subscribe(
            articles => this.articles = articles, 
            err => { 
             console.log(err); 
            }, 
        () => console.log('Searching complete') 
} 

而且目前的功能。

httpWSGetInit() : Observable<Article []> { 

    return this.http.get(R.WEBSITE_URL_WS + this.articlesPagination) 
         .map((res:Response) => res.json()) 
         .catch((error:any) => Observable.throw(error.json().error || 'Server error')); 
} 

工作得很好。

但是http.get方法从未在addScrollListener中调用。

@ViewChild(Content) content: Content; 

ionViewDidLoad() { 
     this.content.addScrollListener(this.onPageScroll); 
} 

onPageScroll(event) { 
     this.httpLoadArticles() 
} 

我试图设置GETsynchronous,但它似乎没有任何改变。这是一个scope的问题?像addScrollListener是纯JS方法,不能附加到angular2容器?

回答

3

是它的范围问题。你应该使用箭头功能来保存这个背景

ionViewDidLoad() { 
    this.content.addScrollListener(() => this.onPageScroll()); 
} 
+0

谢谢你,它的作品像一个魅力:)。你有任何文件吗? – Dinath