我正在使用AngularFireDatabase来获取我的部分数据库,就像这样 db.object('/accounts/'+this.cid); 哪里 this.cid BehaviorSubject 这是可以改变的。我是不是走错了路?
db.object('/accounts/'+this.cid);
this.cid
BehaviorSubject
cid: BehaviorSubject<string>; account: FirebaseObjectObservable<any>; constructor(private db: AngularFireDatabase) { this.cid = new BehaviorSubject<string>('fs2ejD4ds'); this.account = db.object('/accounts/'+this.cid);
基本上每次我跑步的时候 this.cid.next('fhEj2jd') 我希望它能改变我们在Firebase中引用的对象。
this.cid.next('fhEj2jd')
用于从中获取当前值 BehaviorSubject getValue docs .
getValue
this.account = db.object('/accounts/'+this.cid.getValue());
但是请记住,您必须覆盖原始的可观察值 this.account 每次 this.cid 这账户 ,则您必须先取消订阅,然后再使用新的observable覆盖它(对于取消订阅,您可以使用异步管道自动完成)。
this.account
这账户
demo .