Check out this code snippet:
loadNextBatch() {
console.log('scrolldown');
this.pageIndex = this.pageIndex + 1;
this.global.getData(`/conditions/latest?start=${this.pageIndex}&length=${this.pageSize}`)
.pipe(take(1)).subscribe(res => {
const newBatch = res['data'];
if (newBatch.length === 0) {
return false;
}
this.tempThermometer.next(this.tempThermometer.getValue().concat(newBatch));
console.log(this.tempThermometer);
});
}
I am aiming to achieve a functionality where the batch loading stops at start=8
if there is no data available from the API endpoint
/conditions/latest?start=9&length=4
. I want it to only load subsequent batches when there is actual data present.
When there is no data at start=9
, the loading should not proceed to start=11, 12, etc.
. It should stay at start=8
.
The challenge lies in preventing the continuous scrolling down to load more batches beyond start=8
when there is no data at start=9
. The ideal behavior would be for the loading to stop and wait until there is new data available at start=9
before proceeding further.