简体   繁体   English

将数据追加到Observable Angular 2中

[英]Appending data into Observable Angular 2

I am trying to load gif's from the API based on search parameter 20 at a time and once I reach the bottom of the page I need to load 20 more. 我试图一次基于搜索参数20从API加载gif,一旦到达页面底部,我就需要再加载20。 I used observable for this.However, I am not sure how to append the data to my Observable. 我为此使用了observable,但是我不确定如何将数据附加到Observable中。 Every time I scroll to the bottom of the page first 20 results are removed and only new 20 are showing up. 每次我滚动到页面底部时,都会删除前20个结果,并且仅显示新的20个结果。 Can you please help. 你能帮忙吗?

HTML Code: HTML代码:

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

Typescript Code: 打字稿代码:

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 }
        }
      );

Is there a way to append new data into the same "this.observableGifs" observable. 有没有一种方法可以将新数据附加到可观察的相同“ this.observableGifs”中。 Please suggest. 请提出建议。

Try this 尝试这个

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