簡體   English   中英

將數據追加到Observable Angular 2中

[英]Appending data into Observable Angular 2

我試圖一次基於搜索參數20從API加載gif,一旦到達頁面底部,我就需要再加載20。 我為此使用了observable,但是我不確定如何將數據附加到Observable中。 每次我滾動到頁面底部時,都會刪除前20個結果,並且僅顯示新的20個結果。 你能幫忙嗎?

HTML代碼:

<span *ngIf="afterSubmit" (scroll)="onScroll()">
              <a *ngFor="let gif of observableGifs | async"> 
                <iframe [src]="sanitizer.bypassSecurityTrustResourceUrl(gif)"></iframe>
              </a>
            </span>

打字稿代碼:

this.observableGifs = this.gifservice.getGifs(this.gifForm.value,this.offset); ---> My API data comes from this method which I am assigning it to Observable.

    this.observableGifs
      .subscribe((gifs) => { this.gifs = gifs }
        }
      );

有沒有一種方法可以將新數據附加到可觀察的相同“ this.observableGifs”中。 請提出建議。

嘗試這個

this.observableGifs =this.gifservice.getGifs(this.gifForm.value,this.offset); 

this.observableGifs
.subscribe((gifs) => { this.gifs = this.gifs.concat(gifs) }
}

);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM