angular - Waiting for dynamically generated Firebase list observables to finish
问题描述
I'm trying to wait for several dynamically generated observables to finish so I can iterate through Firebase lists. I've tried with both forkJoin and zip but the last line doesn't log anything.
this.db.list<ChatByUser>(`chats_by_user/${this.userService.user.id}`).valueChanges().first().subscribe(chatsByUser => {
const obsArray: Observable<Chat>[] = [];
chatsByUser.forEach(chatByUser => {
obsArray.push(this.db.object<Chat>(`chats/${chatByUser.chatId}`).valueChanges());
});
Observable.zip(obsArray).first().subscribe(chats => console.log(chats));
});
I don't know if it has something to do with it, but I'm using rxjs 6 with rxjs-compat and importing the operators like this:
import { Observable } from "rxjs/Observable";
import "rxjs/add/observable/zip";
解决方案
在将它们添加到数组之前,我需要使用这些 observables。所以添加first()
方法就可以valueChanges()
了。
推荐阅读
- excel - 单元格不会自动更新
- php - Laravel 8:无法创建外键 - “一般错误:1215 无法添加外键约束”
- python - 用python从outlook中提取信息
- python - Python Generic typehint 从类型到实例化对象
- javascript - 自定义确认框引发意外错误
- php - Laravel 8 分页错误 - where 子句中的列“is_deleted”不明确
- r - 使用历史数据 [前期] 创建新变量
- pine-script - TradingView (PINE):如何将成交量图研究整合到价格图研究中?
- python - 写复杂
's 到 C++ 中的纯文本/二进制文件,并将它们读入 NumPy 数组 - python - 根据django中另一个字段中的数字创建字段