我需要你的建议如何将Rxjs 5转换为Rxjs 6。
我的代码如下,我不太确定为什么它不能工作。
Rxjs 5
Observable.from([{amount:5},{amount:10}])
.flatMap(_ => depositService.deposit(depositAmount))
.toArray()
.subscribe(result => {
console.log(result.length);
})Rxjs 6
import { Observable, from, } from 'rxjs';
import { map, catchError, mergeMap} from 'rxjs/operators';
...
const source = from([{amount:5},{amount:10}]);
source
.pipe(mergeMap(_ => depositService.deposit(_.amount).toArray())
.subscribe(result => {
console.log(result.length);
})我得到了错误
您在需要流的位置提供了无效的对象。您可以提供Observable、Promise、Array或Iterable。
发布于 2018-08-14 20:58:01
我认为toArray是一个操作符,应该在管道中传入。
import { Observable, from, } from 'rxjs';
import { map, catchError, mergeMap, toArray} from 'rxjs/operators';
...
const source = from([{amount:5},{amount:10}]);
source
.pipe(
mergeMap(_ => depositService.deposit(_.amount)),
toArray()
)
.subscribe(result => {
console.log(result.length);
})https://stackoverflow.com/questions/51841826
复制相似问题