Firebase / Angularfire2订阅在子事件发生时执行多次

时间:2019-01-25 17:46:21

标签: firebase ionic3 angularfire2

我是Ionic3和Firebase / Angularfire2的新手,订阅功能上有问题。更改子数据时,它将执行多次。

//function that starts the subscribe
listenMatch(isStart){
    let currentUser = this.fireAuth.auth.currentUser.uid;
    this.matchListener = this.db.list('likes', ref => ref.child(currentUser).orderByChild('like').equalTo(true))
        .snapshotChanges().subscribe( snapshot =>{
            console.log(snapshot);
    });
    this.matchListener2 = this.db.list('getLikes', ref => ref.child(currentUser).orderByChild('like').equalTo(true))
        .snapshotChanges().subscribe( snapshot => {
            console.log(snapshot);
    });
}

//this adds a value to firebase that triggers the first "matchListener"
this.db.list('likes', ref => ref.child(currentUser)).set(userID, {
    like: event.like,
    timestamp: firebase.database.ServerValue.TIMESTAMP,
});

我希望“ matchListener”仅返回一个console.log(snapshot)的结果,但是它返回2有时是多次。另一件事,即使“ likes”和“ getLikes” firebase集合具有相同的结构,“ matchListener2”也可以按预期工作。

My firebase database Subscribe Code to trigger subscription Proof that it returns twice

0 个答案:

没有答案
相关问题