Firebase rxfire订阅检查我的代码

时间:2018-10-02 10:51:58

标签: typescript firebase rxjs

您好,因为rxfire是Firebase的新手,所以我只想检查一下这是用它订阅更改的最佳方法,下面的代码可以工作。

https://github.com/firebase/firebase-js-sdk/blob/master/packages/rxfire/docs/database.md

import firebase from 'firebase/app';
import { database, initializeApp } from 'firebase';
import { stateChanges, ListenEvent, object } from 'rxfire/database';
import { map } from 'rxjs/operators';

  const db = firebase.database();
  const ref = db.ref('_data');
  stateChanges(ref).subscribe(change => {

    // console.log(change);
    //console.log(change.snapshot.key);
    //console.log(change.snapshot.val());

    if (change.snapshot.key == '_appConfig') {
      this._appConfig = change.snapshot.val();
      console.log(this._appConfig);
    }


  });

博客参考:https://firebase.googleblog.com/2018/09/introducing-rxfire-easy-async-firebase.html

0 个答案:

没有答案