-1
I’m performing a call to API that returns me a list of any obj when I click on a button. That is if I click twice in sequence, the API returns me the same list in sequence as well.
My question is, how do I make it if I click twice fast in sequence, I cancel the first request and only pick the value of the last click. I tried to use Switmap, but I was not successful. Follow the code below...
getBookingByUserAndStatus(): void
{
this.loading = true;
const getByUserAndStatus = this._bookingsService.getByUserAndStatus(this.user._id, this.statusSelect).subscribe(resp =>
{
console.log(resp);
this.loading = false;
this._foverNotificationService.notify('Lista carregada', SnackbarStatusEnum.success);
},
error =>
{
this.loading = false;
this._foverNotificationService.notify(error, SnackbarStatusEnum.error);
},
() => getByUserAndStatus.unsubscribe());
}
If I click 2 times in sequence on the test button, I get 2 times in sequence the API response as shown in the notification..
Thanks in advance....
It also didn’t work, I edited my question, putting visually what happens!!
– Guilherme Nunes
Try without the
getByUserAndStatus.unsubscribe()
.– Matheus Franco