Is there a way to call a service multiple times? I want to load some data from my DB and in case its a long list, I want to load 1000 entries at each request, if I do something like:
while (!done) { ... }
I will get to many requests to DB that aren't needed but I could get all my data.
This is my method on component.ts
lazyLoadData(): void {
this.getUntil += 1000;
if (this.getUntil > this.totalEntries) {
this.getUntil = this.totalEntries;
}
this.salesService.GetEDISalesReportDetailListLazy(this.id, this.getFrom, this.getUntil)
.then(data => {
if(this.dataTable == null) {
this.dataTable = [];
this.dataTable = data;
this.isDataTableAvailable = true;
this.status = this.dataTable.aaData[0].Status;
} else {
for(let i = 0; i< data.aaData.length; i++){
this.dataTable.aaData.push(data.aaData[i]);
}
this.getFrom = this.getUntil;
}
});
}
And this is my service.ts
GetEDISalesReportDetailListLazy(id: number, startFrom: number, until: number): any {
return this.http2.post(SERVICE_URL + 'Sales/GetEDISalesReportDetailListLazy', { id: id, startFrom: startFrom, until: until }, this.options)
.toPromise()
.then(response => {
return response.json().ReturnStatus.ReturnObject;
})
.catch(this.handleError);
}
Any advice how I can do it? Thank you in advance for the help.