Angular 4 with ngx infinite scroll

后端 未结 1 1851
南方客
南方客 2021-02-06 19:19

I am trying to add an infinite scroll with ngx-infinite-scroll in my Angular 4 project.

The array data has about 800 posts which are from API.

<
相关标签:
1条回答
  • 2021-02-06 19:47

    first, save your original array like this

     this.dataService.getPosts().subscribe((response)=>{                  
                   this.originalPosts = response;
                   this.posts = response.slice(0,20);
              });
    
     onScrollDown(){
       if(this.posts.length < this.originalPosts.length){  
         let len = this.posts.length;
    
         for(i = len; i <= len+20; i++){
           this.posts.push(this.originalPosts[i]);
         }
       }
     }
    

    just push it on the same array you don't need to append it to the table directly, angular will manage itself, its too easy when using angular.

    0 讨论(0)
提交回复
热议问题