I'm trying to migrate an Angular 5 app to Angular 6 and I have this one block of RxJS code that has me stumped. I've Googled and read through the RxJS docs enough to know that I should be using .pipe, but I can't quite get the syntax.
The code returns results from an API call as the user types into a search input field. The new version currently throws the error:
ERROR TypeError: Cannot read property 'call' of undefined
at merge.js:8
at MapSubscriber.project (switchMap.js:9)
Original code:
this.searchResults =
this.form.controls['search'].valueChanges
.debounceTime(200)
.switchMap(query => this.search.searchPeople(query))
.merge(this.clearSearch.mapTo([]));
New version:
this.searchResults = this.form.controls['search'].valueChanges.pipe(
debounceTime(200),
switchMap(query => this.search.searchPeople(String(query)),
merge(this.clearSearch.pipe(mapTo([])))));
I've imported RxJS like this:
import { Observable } from 'rxjs';
import { Subject } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { mapTo } from 'rxjs/operators';
import { merge } from 'rxjs/operators';
import { switchMap } from 'rxjs/operators';