angularfire2订阅中的无限循环

时间:2017-03-30 14:22:19

标签: angular firebase angularfire2

我正在获取数据并将数据添加到订阅中的同一节点。我怎样才能避免无限循环?

this.af.database.list('objects/').subscribe(x=>{   / the subscription is only needed once
  this.af.database.list('objects/').push({newobject: ''};
};

1 个答案:

答案 0 :(得分:4)

如果我错了,请拍我,但我相信你可以使用first()方法:

this.af.database.list('objects/').first().subscribe(x=>{ 
  this.af.database.list('objects/').push({newobject: ''};
};
相关问题