您好,因为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