I'm upgrading an application from Angular 4 to Angular 5, and have the following code in a service
loadRefData(): Observable<RefData> {
return this.participant$.switchMap((role) => {
return this.http.get(`${this.API_URL}/${role}/participantGroups/refdata`)
.map(refData => refData as RefData);
});
Since Angular 5 comes with the minimum requirement of RxJS 5.5.2, I'm converting it to use lettable operators with the .pipe() operator.
I thought I could do this
loadRefData(): Observable<RefData> {
return this.participant$.switchMap((role) => {
return this.http.get(`${this.API_URL}/${role}/participantGroups/refdata`)
.pipe(
map(refData => refData as RefData);
);
});
but I get the error TypeError: this.participant$.switchMap is not a function. I get no compilation errors from the typescript compiler though.
this.participant$ is of type Observable<string>, and unless I'm mistaken I should be able to perform a switchMap on it.
What am I missing?
This is with typescript@^2.6.1, rxjs@^5.5.2.
EDIT:
I just noticed that this.participant$ which is populated from ngrx\store.select is of type Store<string>.
switchMapis an operator as well so you need to use it inside.pipe()likethis.participant$.pipe(switchMap(role => ...))- martin'rxjs/operators'. @martin That seems to have done the trick! I thought I had tried that already but who knows! Consider posting it as an answer. - Daniel B