【发布时间】: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进行日志记录操作。