2016-12-18 7 views
1

私は自分のコンポーネント内で観測可能なfirebaseオブジェクトを購読しています。このサブスクライブは、観測可能なスイッチが真から偽に切り替わるとき、またはその逆のときにリッスンします。 は現在、これは私のために働いて、それだけで私はそれがデータベースに正しく変更されていることを知っているにもかかわらず、偽(初期値を吐き出していません。コンポーネントの変更内で観測可能な購読が動作しない

サービス

private ReadyObs; 

SetRoom(){ 
    this.Room = this.AngularFire.database.object('/Rooms/ABC1'); 
    this.Room.subscribe(snap => { 
     if(snap.$value !== null){ 
      this.ReadyObs = this.AngularFire.database.object(`/Rooms/${player.room}/Ready`); 
     } 
    } 
} 

checkReady(){ 
    return this.ReadyObs; 
} 

コンポーネント

private ReadyObs=this.main.checkReady(); 

//Always results with still not ready even though its true 
this.ReadyObs.subscribe((result) =>{ 
    if(result === true) 
     console.log("Ready to use"); 
    else 
     console.log("Still not ready"); 
}); 

答えて

0

ご購読はfalseで、サブスクリプションの初期値だけを取っている。私はあなたが科目を使用して見てお勧めします。 Subject manual link

探しているのが粗い場合は、hereでした。

this.ReadyObs=new Rx.BehaviorSubject<boolean>(false); 
this.ReadyObs.subscribe((result) =>{ 
if(result === true) 
    console.log("Ready to use"); 
else 
    console.log("Still not ready"); 
}); 

と私は理解していないのです

this.Room.subscribe(snap => { 
    if(snap !== null){ 
     self.ReadyObs.next(true); 
    } 
    }); 
+0

、それは例を残したり、手の込んだすることは可能でしょうか? –

+0

あなたはReadyObsをチェックしていますが、これはFirebaseオブジェクトを正しく聞くことになっていますか? –

+0

ReadyObsはどこで正確に設定していますか? –

関連する問題