Angular typeahead with RxJs switchMap subscribe

Developer

Using Angular bootstrap Typeahead 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?

(<any>window).resolveJsonReferences(this.colorService.searchColors(term))

Typeahead with RxJs SwitchMap

 search = (text$: Observable<string>) =>
    text$
    .debounceTime(200)
    .distinctUntilChanged()
    .do(() => this.searching = true)
    .switchMap(term =>
        this.colorService.searchColors(term) // Json result needs circular reference resolver
        .do(() => this.searchFailed = false)
        .catch(() => {
            this.searchFailed = true;
            return Observable.of([]);
        }))
    .do(() => this.searching = false);

In Other places

return this.colorService.searchColors(term)
        .subscribe(
        res => {               
            this.colors= this.utilities.resolveJsonReferences(res);
        },
        err => {               
        });
Teddy Sterne

Just map the value through your resolver.

.map((term) => this.utilities.resolveJsonReferences(term))

All together:

search = (text$: Observable<string>) =>
    text$
    .debounceTime(200)
    .distinctUntilChanged()
    .do(() => this.searching = true)
    .switchMap(term =>
        this.colorService.searchColors(term) // Json result needs circular reference resolver
        .map((term) => this.utilities.resolveJsonReferences(term))
        .do(() => this.searchFailed = false)
        .catch(() => {
            this.searchFailed = true;
            return Observable.of([]);
        }))
    .do(() => this.searching = false);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

RxJs switchMap with angular HttpClient

angular and RxJS/switchMap

return for SwitchMap in Rxjs - Angular

Api typeahead search using RxJs switchMap sending too many requests (angular)

Angular: RxJs switchMap producing error

rxjs switchMap not working in Angular Guard?

subscribe keys of and observable in Angular/RxJS

Angular / RXJS - How to perform logic after a switchMap

Angular2 rxjs - switchmap catch error

Initialization of rxjs observables, switchMap with Angular routing

Angular RxJS Subscribe to HTTP Request in HTTP Request

rxjs 6 countdown timer subscribe angular 6

angular 2 rxjs subscribe to observable code not executing

Realtime searching in Angular with RxJS tap vs subscribe

Angular 2 return data from RxJs subscribe

angular2 rxjs shared subscribe not firing

angular RXJS how to cast subscribe response type

Angular resolve Rxjs map and subscribe multiple APIs

Angular RxJS Nested Subscribe with multiple Http Requests

Unsubscribe in a condition does not allow to subscribe in Angular RXJS

How to use subscribe-next RxJS in Angular?

Angular Rxjs Observable items count doubles on subscribe

testing rxjs catchError and subscribe scenarios in jest and Angular

How to subscribe to switchMap

chaining observables with switchmap and forkjoin not working as expected angular typescript rxjs

I dont get rxjs 6 with angular 6 with interval, switchMap, and map

Angular Testing - Chained HTTP Requests using rxjs switchMap

angular 5 unit tests fail when rxjs switchmap used

Angular6: RxJS switchMap operator is not working as expected