如何在Angular7中实现无限滚动分页?

问题描述 投票:0回答:1

我有一个对象,我想发送params。 所以ngOnInit工作,但我需要onScrollDown每次滚动时添加到我的参数pageNumber + 1。 我怎样才能做到这一点 ?

questionListParams = {
    pageNumber: 1,
    pageSize: 10,
};


ngOnInit() {
    this.questionsHttpRequests.getQuestions(this.questionListParams).subscribe((response) => {
        this.listOfQuestions = response;
    });
}


onScrollDown() {
    this.questionsHttpRequests.getQuestions((this.questionListParams)).subscribe((response) => {
        this.listOfQuestions.push(...response);
    });
}
angular pagination angular7 infinite-scroll
1个回答
0
投票

您可以在拨打电话之前或之后递增。

onScrollDown() {
// Before
this.questionListParams.pageNumber++; 
 this.questionsHttpRequests.getQuestions((this.questionListParams)).subscribe((response) => {
        this.listOfQuestions.push(...response);
    });
// Or after
this.questionListParams.pageNumber++; 
}
© www.soinside.com 2019 - 2024. All rights reserved.