When you click on the button, the getDatafromServer method is triggered. Tell me if switchMap is implemented correctly in Angular for one route. when pressed again, the previous request is canceled (if the old one has not yet arrived) and a new one is sent:
getDatafromServer() { of(`url1`).pipe(switchMap(url => this.httpGeneralService.getDataFromJsonServer(url))). subscribe(i => console.log(i)); } It seems to be true, but in the browser in the Network it is not visible that previous requests are canceled.
UPD: this version seems to be working:
private requestPasswordSubject$ = new Subject(); private requestPassword = this.requestPasswordSubject$.pipe( switchMap(() => this.httpGeneralService.getDataFromJsonServer(`url1`)) ) .subscribe(response => { console.log(response); } ); getDatafromServer() { this.requestPasswordSubject$.next(); }