[AngularFire] Resolve snapshotChanges doesn't emit value when data is empty
2024-10-01 18:01:20
Updated to AngularFire2 v5.0.
One important change is that you need to call .snapshotChanges() or .valueChanges() to get data as Observable back.
return this.db.list<Skill>(`skills/${this.uid}`)
.snapshotChanges()
The problem is when there is no data, .snapshotChanges() never emit a value.
Luckly it is Observable, we can solve the problem by using .startWith():
getSkills(): Observable<Skill[]> {
return this.db.list<Skill>(`skills/${this.uid}`)
.snapshotChanges()
.startWith([])
.map((actions) =>
actions.map((action) => ({$key: action.key, ...action.payload.val()}))
);
}
If there is no data coming back from firebase, we still emit a empty array. This is much friendly if you work with Ngrx. Because if you depends on .snapshotChange() to emit a value back to switch map to next action, it might just block there, and your next action will never get dispatched.
最新文章
- position: fixed用在iframe里面失效了
- 【转】ubuntu vpn自动切换路由
- js读书笔记
- 反射 + 抽象工厂模式切换DB数据源(附Demo)
- C#线程并发执行的实例[转]
- c# 调用分页(控制器端的)与时间的格式
- 气象API(2)
- Spring3 整合Hibernate3.5 动态切换SessionFactory (切换数据库方言)
- java连接mysql批量写入数据
- Javascript教程:AngularJS的五个超酷特性
- iis7如何取消目录的可执行权限
- PureMVC(JS版)源码解析(三):Observer类
- noip201506 Message 信息传递
- 第四节 mount /who / mkdir /rmdir /rm /cp /mv /touch /cat /tac/head /tail /more /less / chmod /chown /umask /chattr /lsattr /history /echo
- Linux显示版本信息并退出
- WebSocket整合SSM(Spring,Struts2,Maven)
- windows系统dokuwiki安装部署设置 xampp环境配置
- AndroidStudio中如何使用GsonFormat
- java web(三):ServletContext、session、ServletConfig、request、response对象
- SimpleDateFormat的parse(String str)方法的用法