rxjs - 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');
});
为什么第二个版本有效,但第一个无效?
解决方案
from
接受多个参数,map
ofArray
将当前元素的索引作为第二个参数发送。因此.map(from)
与 相同.map((value, index, sourceArray) => from(value, index, sourceArray))
。怎么了。
推荐阅读
- angular - 角垫滑动切换和数字输入
- angular - httpclient.post / 向 API 发送数据不与 formData.append 一起使用,但与 body.set 一起使用
- android - AutoCompleteTextView onCommitCompletion 不起作用
- javascript - 关于如何在反应中使用地图功能渲染这些数据的任何建议?
- python - 如何使 Selenium python 代码更高效
- python-3.x - DRF - 在 serializers.Serializer 中渲染 SerializerMethodField
- facebook - Facebook 错误代码的定义 = 190 子代码 = 2069032
- javascript - 将斐波那契数列打印到 (n)
- spartacus-storefront - 依赖库未编译的詹金斯管道中的错误
- jwt - 赛普拉斯如何从本地存储返回 JWT 令牌并在另一个 api 调用中使用它