【发布时间】:2016-12-17 06:32:54
【问题描述】:
现在我有一个间隔来检查我的 observable 是否每 1 秒发生一次变化。我知道这不是最有效的方法,但我不知道如何直接在组件中监听状态变化并在它发生时运行函数。这是我现在的间隔:
更新 1: 我现在正在使用订阅,但这仍然不适合我。我从一个已经订阅的 observable 发送一个可观察的 firebase 对象。这是我的问题所在吗?
服务
private ReadyObs;
SetRoom(){
this.Room = this.AngularFire.database.object('/Rooms/ABC1');
this.Room.subscribe(snap => {
if(snap.$value !== null){
this.Ready = 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");
});
【问题讨论】:
标签: angular rxjs observable