1

I want to work with switchMap for my http request instead of unsubscribing my pending requests.

I am getting following info for the code below:

The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'

sub = new BehaviorSubject({});

let result: Observable<any> = this.sub.next(this.urlShortenerForm.value);
  const result: Observable<Object> = this.sub.pipe(
    switchMap((term) => this.getData(term));
 );

getData(da): Observable<Object> { 
  //Here I will send my request to server over services
  return of(da);
}
Noah Tony
  • 373
  • 3
  • 7
  • 18
  • I'm probably missing something here, but why wouldn't you need to unsubscribe if you use `switchMap`? (Also, you've declared 2 variables both called `result` there) – user184994 Aug 25 '18 at 21:36
  • Well, lets assume I will send one request and it is still pending and then I decide to switch to another site but the first request is still pending. The first request I need to cancel and for that I want use switchMap instead of – Noah Tony Aug 25 '18 at 21:41
  • you just need to add timeout https://stackoverflow.com/questions/45938931/angular-httpclient-default-and-specific-request-timeout – mohamed Aug 25 '18 at 22:12

0 Answers0