2016-11-21 59 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