离子无限滚动不会影响结果

时间:2020-09-12 18:08:52

标签: angular typescript ionic-framework


我正在使用离子无限滚动每次到达底部时获得更多帖子
它可以正常工作,但可以代替未连接的结果
这是代码
page=0

  getAllposts() {

    const url = `${this.API_URL}/getallposts?page=${this.page}`;

    return this.http.get<any[]>(url);
  }

getAllList() {
  this.getAllposts().subscribe(data => {
    this.showPosts = this.showPosts.concat(data) as PostModel[];

  
  });
} 



loadData(event) {

setTimeout(() => {
this.getAllList()
    event.target.complete();
  }, 2000);

this.page++
}
 

2 个答案:

答案 0 :(得分:0)

请尝试使用[代替for loop

cancat

答案 1 :(得分:0)

您可以在此处使用spread operator

this.showPosts = [...this.showposts,...data];

Reference