angular - 我需要像 combineLatest 这样的东西,但是当任何可观察的发射时
问题描述
所以我的代码是:
combineLatest([obs1, obs2]).subscribe((x => {
console.log(x)
})
当 EITHER observable 发出时,应该触发 log 语句。但是,文档中有一个问题:
在每个 observable 发出至少一个值之前, combineLatest 不会发出初始值
即使原始可观察对象之一从未发出,我也需要它发出。我该怎么做?很多谢谢
解决方案
每个可观察对象的典型用法 startWith
combineLatest([
obs1.pipe(startWith(null)),
obs2.pipe(startWith(null)]
).subscribe((x => {
console.log(x)
})
推荐阅读
- excel - 比较两个工作表并将匹配项和唯一值粘贴到同一工作簿的不同工作表中
- c - 为什么 GCC -O0 转换按位与并乘以分支?
- xml - 使用 XSLT 将密钥添加到 XML 中的所有子节点到 MS Access 传输
- c++ - 网格未在 Assimp 中加载
- anylogic - Anylogic:为什么在编译过程中会出现“错误:无法解决”?
- .net - F# 相同的程序集提供不同的性能
- javascript - 为什么 TypeScript 会生成旧的 JS 文件?
- azure-devops - 开发者 ID 在审批和检查中不可见
- ruby-on-rails - 如何从给定的 acces_token 获取 user_id 到 rails API(我使用 google omniAuth)
- prometheus - 如何仅获取面板在可配置时间段内的请求数