title: What is SwitchMap in RxJS
body: <p>I'm using Restangular in my Angular 5 project. In <a href="https://github.com/2muchcoffeecom/ngx-restangular#adderrorinterceptor" rel="nofollow noreferrer">addErrorInterceptor section</a>, if you look at the code it calls the <code>refreshAccesstoken</code> method and then gets the new access token in <code>switchMap</code> part. By now I'm returning a <code>replySubject</code> in my <code>refreshAccesstoken</code> method so if I subscribe to the return value, I can get the new access token but I'm not able to get it in switchMap as I don't know what it is (I've also searched for switchMap but I just found some functions which didn't help me).</p>
  
  <p>Here is my code for AuthService.refreshAccessToken:</p>
  
  <pre><code>refreshAccessToken() {
    let resultSubject: ReplaySubject&lt;any&gt; = new ReplaySubject&lt;any&gt;();
    const url = this.AUTH_URL + 'oauth/token';
    const requestOptions = {
      headers: new Headers({
        authorization: 'Basic ' + btoa(this.clientId + ':' + this.clientSecret),
        'Content-Type': 'application/x-www-form-urlencoded'
      })
    };
    const body = {
      grant_type: 'refresh_token',
      refresh_token: this.refreshToken,
      // scope: ''
    };
    let params = this.utilityService.convertObjectToURLParams(body);
  
    this._http.post(url, params.toString(), requestOptions).subscribe(
      response =&gt; {
        let result = response.json();
        // console.log('refreshed_access_token', result);
        this.accessToken = result.access_token
        this.refreshToken = result.refresh_token
        this.expireIn = result.expire_in
        resultSubject.next(this.accessToken);
      },
      error =&gt; {
        resultSubject.error(error);
      }
    );
    return resultSubject;
  }
  </code></pre>