<string>Observable.switchMap 不是函数



我正在将应用程序从 Angular 4 升级到 Angular 5,并在服务中具有以下代码

loadRefData(): Observable<RefData> {
return this.participant$.switchMap((role) => {
return this.http.get(`${this.API_URL}/${role}/participantGroups/refdata`)
.map(refData => refData as RefData);
});

由于 Angular 5 具有 RxJS 5.5.2 的最低要求,因此我将其转换为将可出租运算符与.pipe()运算符一起使用。

我以为我可以做到

loadRefData(): Observable<RefData> {
return this.participant$.switchMap((role) => {
return this.http.get(`${this.API_URL}/${role}/participantGroups/refdata`)
.pipe(
map(refData => refData as RefData);
);
});

但我得到错误TypeError: this.participant$.switchMap is not a function.不过,我没有从打字稿编译器收到编译错误。

this.participant$属于Observable<string>型,除非我弄错了,否则我应该能够对它进行switchMap

我错过了什么?

这是与typescript@^2.6.1rxjs@^5.5.2

编辑: 我刚刚注意到从ngrxstore.select填充的this.participant$Store<string>

这是从Angulars博客中引用的一句话,可能会对您有所帮助。

HttpClient

在 4.3 版中,我们在@angular/common中以更小的 HttpClient 的形式交付了 在 Angular 中发出 Web 请求的更简单、更强大的方式。新的 HttpClient得到了开发人员的好评,所以我们现在 建议所有应用程序使用 HttpClient,并弃用 以前的@angular/http库。

要更新到 HttpClient,您需要将HttpModule替换为 从每个模块中的@angular/common/httpHttpClientModule, 注入 HttpClient 服务,并删除任何map(res => res.json())不再需要的调用。

来源: 角度 5

最新更新