将Firebase onAuth回调绑定到observable

时间:2016-03-02 14:14:59

标签: firebase angular rxjs observable

我尝试将Firebase中onAuth()请求的回调绑定到RxJS可观察对象。

let auth = Observable.bindCallback(ref.onAuth);
let source = auth();
let subscription = source.subscribe(
    (x) => console.log(x),
    (e) => console.log(e)
);

我收到错误:

  

无法阅读财产' O'在BoundCallbackObservable.X.Ig [as callbackFunc]

中未定义

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

似乎问题是执行了错误的上下文回调函数。这应该解决它:

let auth = Observable.bindCallback(ref.onAuth.bind(ref));