首页 文章

可观察的<string> .switchMap不是函数

提问于
浏览
1

我正在将应用程序从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() 运算符的lettable运算符 .

我以为我能做到这一点

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 . 但是我没有从typescript编译器中获得编译错误 .

this.participant$ 的类型为 Observable<string> ,除非我弄错了,否则我应该可以执行 switchMap .

我错过了什么?

这是 typescript@^2.6.1rxjs@^5.5.2 .

编辑:我刚刚注意到 ngrx\store.select 填充自 ngrx\store.select 的类型为 Store<string> .

1 回答

  • -1

    这是来自Angulars博客的报价,可能对你有所帮助 .

    HttpClient在4.3版本中,我们在@ angular / common中发布了HttpClient,它是一种更小,更简单,更强大的方式,可以在Angular中发出Web请求 . 新的HttpClient得到了开发人员的一致好评,所以我们现在推荐所有应用程序使用HttpClient,并弃用以前的@ angular / http库 . 要更新到HttpClient,您需要在每个模块中用@ angular / common / http替换HttpModule和HttpClientModule,注入HttpClient服务,并删除任何map(res => res.json())调用,这些调用是不再需要 .

    资料来源:Angular 5

相关问题