Issue
I have this function that calls a service to get data through api. I would like after the first call, if result is equal to 50, another call is made with updated offset. But this doesn't work. It doesn't go into the arrow function:
result: any[] = []
async getData(v) {
await this.gs.getMaxGifs(v, this.offset).subscribe((response: any) => {
this.result.push(...response.data);
this.offset += 50;
if (this.result.length % 50 == 0) {
console.log('DENTRO')
async () => {
await this.gs.getMaxGifs(v, this.offset).subscribe((response: any) => {
console.log('DENTRO22222')
})
this.result.push(...response.data);
this.offset += 50;
}
}
console.log(this.result.length)
});
}
When this then works, I want to replace the if with the while. If I insert it now it goes into an infinite loop
Solution
As commented it worked for sirss,
async getData(v) {
await this.gs.getMaxGifs(v, this.offset).subscribe((response: any) => { this.result.push(...response.data);
this.offset += 50; if (this.result.length % 50 == 0) {
console.log('DENTRO');
this.getData(v);
}
console.log(this.result.length) });
Answered By - Deepak Jha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.