2017-07-26 8 views
0

私はデータにjsonを使用しています。私がしたいことは、データがもう利用できなくなったら無限スクロールを終了する必要があるということです。 これをどのように実装できますか。イオニック3無限スクロール終了多くのデータが見つからない場合

loadData(currentCount) { 
    this.http.get('http://www.exapmle.com/feed.php?page=' + this.currentCount).map(res => res.json()).subscribe(data => { 
     this.posts1 = data; 
     let i = 0; 
     for (let v in this.posts1) { 
      if (i < 4) { 
       this.slidesdata.push(this.posts1[v]); 
      } else { 
       this.posts.push(this.posts1[v]); 
      } 
      i++; 
     } 
    }); 
} 

    doInfinite(infiniteScroll: any) { 
    this.currentCount = this.currentCount + 1; 
    this.http.get('http://www.exapmle.com/feed.php?page=' + this.currentCount).map(res => res.json()).subscribe(data => { 
     this.newposts1 = data; 
     this.newposts = this.newposts1; 
     for (let i in this.newposts) { 
      this.posts.push(this.newposts[i]); 
     } 
     infiniteScroll.complete(); 
    }); 
} 

答えて

0

使用*ngIf - は、ここでは、コードです。

HTML:

 <ion-infinite-scroll (ionInfinite)="doInfinite($event)"> 
      <ion-infinite-scroll-content loadingText="Loading your leads..." *ngIf="pagingEnabled"></ion-infinite-scroll-content> 
     </ion-infinite-scroll> 
<div *ngIf="!pagingEnabled"> No more data is available.</div> 

TS

public pagingEnabled: boolean = true; 

doInfinite(infiniteScroll: any) { 
     this.currentCount = this.currentCount + 1; 
     this.http.get('http://www.exapmle.com/feed.php?page=' + this.currentCount).map(res => res.json()).subscribe(data => { 
      this.newposts1 = data; 
      this.newposts = this.newposts1; 
      if (this.newposts.length) { 
       for (let i in this.newposts) { 
        this.posts.push(this.newposts[i]); 
       } 
      } else { 
       this.pagingEnabled = false; 
      } 

      infiniteScroll.complete(); 
     }); 
    } 
+0

私はこれらの行をマージする場合は、2ページからのデータはない負荷を行い、そして、私はそれらをマージいけない場合、私は同じ取得私が前に持っていたエラー - 予期しないトークン<0の位置のJSONで –

+0

あなたは無限にスクロールしましたか? –

+0

はい、動作しますが、一度データを読み込むページがなくなると、このエラーが発生します。 –

関連する問題