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.

[AngularFire] Resolve snapshotChanges doesn't emit value when data is empty的更多相关文章

  1. [AngularFire] Firebase OAuth Login With Custom Firestore User Data

    import { NgModule } from '@angular/core'; import { AuthService } from './auth.service'; import { Ang ...

  2. Angular $scope和$rootScope事件机制之$emit、$broadcast和$on

    Angular按照发布/订阅模式设计了其事件系统,使用时需要“发布”事件,并在适当的位置“订阅”或“退订”事件,就像邮箱里面大量的订阅邮件一样,当我们不需要时就可以将其退订了.具体到开发中,对应着$s ...

  3. Emit学习(4) - Dapper解析之数据对象映射(一)

    感觉好久没有写博客了, 这几天有点小忙, 接下来会更忙, 索性就先写一篇吧. 后面估计会有更长的一段时间不会更新博客了. 废话不多说, 先上菜. 一.示例 1. 先建类, 类的名称与读取的表名并没有什 ...

  4. es6中promise ALL Race Resolve Reject finish的实现

    function mypromise(func){ this.statue = "pending"; this.data = null; this.resolveCallback ...

  5. AngularJS路由系列(5)-- UI-Router的路由约束、Resolve属性、路由附加数据、路由进入退出事件

    本系列探寻AngularJS的路由机制,在WebStorm下开发.主要包括: ● UI-Router约束路由参数● UI-Router的Resolve属性● UI-Router给路由附加数据● UI- ...

  6. angular之$broadcast、$emit、$on传值

    文件层级 index.html <!DOCTYPE html> <html ng-app="nickApp"> <head> <meta ...

  7. seajs源码分析

    seajs主要做了2件事 1.定义什么是模块,如何声明模块:id.deps.factory.exports ----define=function(id,deps,factory){return ex ...

  8. 自己修改的两个js文件

    sea-base.js /** * Sea.js 2.2.3 | seajs.org/LICENSE.md */ (function(global, undefined) { // Avoid con ...

  9. Dapper的完整扩展(转)

    真心想说:其实...我不想用Dapper,如果OrmLite.Net支持参数化的话,也就没Dapper的什么事情了,对于OrmLite.Net只能做后续跟踪...... 这个其实是看了Dapper作者 ...

随机推荐

  1. 紫书 例题 10-17 UVa 1639(数学期望+分数处理+处理溢出)

    设当前有k个,那么也就是说拿到其他图案的可能是(n-k)/n 那么要拿到一个就要拿n/(n-k)次 所以答案就是n(1/n + 1/(n-1) ......1/2 + 1 / 1) 看起来很简单,但是 ...

  2. WHU 1538 Stones II 动态规划

    赛后写的,动态规划,学长和题解,提供了两种状态设计的思路,都写了下……结果在写第二种的时候,不小心把下标的起点写错了,导致WA了无数发…… 无奈啊……每次都是这种错误…… 题意: 大概就是有n块石头, ...

  3. Spring可扩展Schema标签

    基于Spring可扩展Schema提供自己定义配置支持 http://blog.csdn.net/cutesource/article/details/5864562 WARN : org.sprin ...

  4. android 聊天室窗体

    public class MainActivity extends Activity { ScrollView scrollView; Button button; LinearLayout layo ...

  5. eclipse C开发添加自己的头文件搜索路径

    eclipse编译C程序时提示: ..\src\main.c:8:21: fatal error: my_type.h: No such file or directory 如图: 需要添加自己的头文 ...

  6. ZOJ 2588 Burning Bridges(求桥的数量,邻接表)

    题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2588 Burning Bridges Time Limit: 5 ...

  7. 让透明div里的文字不透明

    最近在工作中遇到一个问题,我在div里写上文字,当我把div变为半透明的时候,里面的文字也会随之透明.情况如下: <div class="box"> 这是一段不应该透明 ...

  8. codeforces 710C Magic Odd Square(构造或者n阶幻方)

    Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both ma ...

  9. Firefox 浏览器添加Linux jre插件

    在安装 Java 平台时,Java 插件文件将作为该安装的一部分包含在内.要在 Firefox 中使用 Java,您需要从该发行版中的插件文件手动创建符号链接指向 Firefox 预期的其中一个位置. ...

  10. Flex4之事件详解

    第一.Flex事件简介 事件贯穿于Flex应用开发的全过程.事件是ActionScript .0中最重要的部分之一,也是Flex应用程序开发的核心基础.本章将在DOM 3的基础上详细讲解ActionS ...