I'm facing an issue with a function that calls a service to retrieve data via an API. The goal is to make another call with an updated offset if the result equals 50 after the first call. However, despite my efforts, it seems like it doesn't enter the arrow function as expected:
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)
});
}
https://i.sstatic.net/RziOM.png
Once I get this part working, my plan is to replace the if statement with a while loop. But when I tried to add it now, it resulted in an infinite loop.