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

时间:2019-03-15 15:01:13

标签: angular pagination angular7 infinite-scroll

我有一个带有要发送的参数的对象。
因此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);
    });
}

1 个答案:

答案 0 :(得分:0)

您可以在拨打电话之前或之后进行通话。

onScrollDown() {
// Before
this.questionListParams.pageNumber++; 
 this.questionsHttpRequests.getQuestions((this.questionListParams)).subscribe((response) => {
        this.listOfQuestions.push(...response);
    });
// Or after
this.questionListParams.pageNumber++; 
}
相关问题