0

I have a form control input to search for results.

component.html

<input matInput [formControl]="input">

I'm using valueChanges observable to check for changes.

component.ts

this.xx = this.input.valueChanges.pipe(
  switchMap(res => {
    return this.someService.test(res);
  }),
);

What i don't understand is that on fast typing the cancellation of the previous http request is only working on some of the endpoints.

someService.ts

public test(q: string): Observable<any> {
  // api-1 cancelling
  return this.http.get<any>('http://localhost:8080/api/geosuggestion?q=' + q);
  // api-2 not cancelling
  // return this.http.get<any>('http://localhost:8080/api/items?q=' + q, { headers: { 'auth-token': this.authService.getToken() } });
}

Similar questions always origin from the fact that they used different obsersvable chains. In my case there has to be a different reason as i'm using the exact same logic in both cases and only replace the endpoint url.

api-1 (successfully cancelling) api-1 screenshot

api-2 (not cancelling) api-2 screenshot

Why is switchMap cancellation only working on some of my endpoints?

F.H.
  • 1,456
  • 1
  • 20
  • 34

0 Answers0