此代码片段在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?
答案 0 :(得分:1)
我自己弄清楚了:我从“ rxjs / observable / forkJoin”而不是“ rxjs”导入了错误的forkJoin。