首页 > 解决方案 > rxjs : zip(...promiseArray.map(from)) -> throws "undefined is not a function (near 'scheduler.schedule...)"

问题描述

rxjs 的奇怪行为。getPromise是一个返回 Promise 的异步函数。当我运行这个脚本时,它会抛出一个异常TypeError : undefined is not a function (near 'scheduler.schedule...')

zip(...[getPromise(), getPromise()].map(from)).subscribe(() => {
    console.log('hey');
});

但这会起作用(注意里面的区别map):

zip(...[getPromise(), getPromise()].map(p => from(p))).subscribe(() => {
    console.log('hey');
});

为什么第二个版本有效,但第一个无效?

标签: rxjs

解决方案


from接受多个参数,mapofArray将当前元素的索引作为第二个参数发送。因此.map(from)与 相同.map((value, index, sourceArray) => from(value, index, sourceArray))。怎么了。


推荐阅读