Staram się zrobić infinite scrolla. Po dojechaniu do dolnej krawędzi ma pobrać nowe itemy listy i zmergować je z obecnym observable, który trzyma dotychczasową listę itemów. Problem w tym, że każdego kolejnego scrolla wykonuje również nadmiarowe requesty po historyczne dane. Wygląda to tak, jakby this.items$ emitowało wszyskie poprzednie stany. Co robię źlę? Podpowiecie? ;)
@PIENSCI_WONSZA: a o po co samemu? użyj ngx-infinite scroll. a jak juz robisz tak jak robisz to użyj BehaviorSubject i tam trzymaj dane, dorzucaj do niego to co zaciagniesz
Co robię źlę? Podpowiecie? ;)
items$: Observable;
page = 1;
pageSize = 20;
isLoading = true;
constructor(private itemsService: ItemsService) { }
ngOnInit() {
this.items$ = getItems();
}
onScroll() {
this.page++;
this.items$ = combineLatest([
this.items$,
this.getItems()
])
.pipe(
map(([currentItems, newItems] => [...currentItems, ...newItems ]))
)
}
private getItems() {
return this.itemsService
.getItems({ page: this.page, pageSize: this.pageSize })
.pipe(
map((res) => res.items)
);
}
#angular #angularjs