title: Angular typeahead with RxJs switchMap subscribe
body: <p>Using <a href="https://ng-bootstrap.github.io/#/components/typeahead/examples" rel="nofollow noreferrer">Angular bootstrap Typeahead</a> plugin to show colours. But I need to resolve the circular references like in the other places I used. I cant make it with RxJs SwitchMap operator. Is there any other possible way to resolve?</p>
  
  <p><code>(&lt;any&gt;window).resolveJsonReferences(this.colorService.searchColors(term))</code></p>
  
  <p><strong>Typeahead with RxJs SwitchMap</strong></p>
  
  <pre><code> search = (text$: Observable&lt;string&gt;) =&gt;
      text$
      .debounceTime(200)
      .distinctUntilChanged()
      .do(() =&gt; this.searching = true)
      .switchMap(term =&gt;
          this.colorService.searchColors(term) // Json result needs circular reference resolver
          .do(() =&gt; this.searchFailed = false)
          .catch(() =&gt; {
              this.searchFailed = true;
              return Observable.of([]);
          }))
      .do(() =&gt; this.searching = false);
  </code></pre>
  
  <p><strong>In Other places</strong></p>
  
  <pre><code>return this.colorService.searchColors(term)
          .subscribe(
          res =&gt; {               
              this.colors= this.utilities.resolveJsonReferences(res);
          },
          err =&gt; {               
          });
  </code></pre>