【问题标题】:Angular 6, rxjs 6 forkJoin an mapAngular 6, rxjs 6 fork加入地图
【发布时间】:2018-10-15 06:54:28
【问题描述】:

此代码片段在 Angular 4 中按预期工作:

Observable.forkJoin(
  Observable.of('test1'),
  Observable.of('test2')
).map(result => {
  console.log(result);
}).subscribe();

这里的剪辑不再适用于 rxjs 6:

forkJoin(
  of('test1'),
  of('test2')
).pipe(map(result => {
  console.log(result);
})).subscribe();

我得到以下编译错误:

ERROR in app/services/bundles/karaf-bundles.service.ts(47,12): error TS2345: Argument of type 'OperatorFunction<[string, string], void>' is not assignable to parameter of type 'OperatorFunction<any, any>'.
  Types of parameters 'source' and 'source' are incompatible.
    Type 'Observable<any>' is not assignable to type 'Observable<[string, string]>'.
      Types of property 'source' are incompatible.
        Type 'import("/Users/moritzvieli/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/moritzvieli/repo/cltmgmtconsole/web/node_modules/rxjs/internal/Observable").Observ...'.
          Types of property 'source' are incompatible.
            Type 'import("/Users/moritzvieli/node_modules/rxjs/internal/Observable").Observable<any>' is not assignable to type 'import("/Users/moritzvieli/repo/cltmgmtconsole/web/node_modules/rxjs/internal/Observable").Observ...'.

如何在 Angular 6 中映射一个 forkjoin?

【问题讨论】:

  • 使用tap 而不是map 进行日志记录操作。

标签: angular rxjs angular6


【解决方案1】:

我自己想通了:我从“rxjs/observable/forkJoin”而不是“rxjs”导入了错误的forkJoin。

【讨论】:

  • yes rxjs v6 简化了命名空间,现在只有rxjsrxjs/operators
猜你喜欢
  • 2018-09-23
  • 2019-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-15
  • 2018-12-19
相关资源
最近更新 更多