2

I am trying to fetch datas on scroll and fill an array of "Article[]".

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

And the current function.

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'));
}

Works pretty well.

But the http.get method is never called in addScrollListener.

@ViewChild(Content) content: Content;

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

onPageScroll(event) {
       this.httpLoadArticles()
}

I tried to set the GET as synchronous but it seems to not change anything. Is it a scope issue ? Like addScrollListener is a pure JS method and cannot be attached to angular2 container ?

1 Answer 1

3

Yes its an scope issue. You should use Arrow function to preserve this context

ionViewDidLoad() {
    this.content.addScrollListener(() => this.onPageScroll() );
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it works like a charm :). Do you have any documentation on it ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.