daniel
daniel

Reputation: 35693

Endless loop in angularfire2 subscription

I am getting data and add data to the same node within an subscription. How can I avoid the endless loop?

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

Upvotes: 3

Views: 274

Answers (1)

Poul Kruijt
Poul Kruijt

Reputation: 71891

Shoot me if I'm wrong, or don't, but I believe you can use the first() method:

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

Upvotes: 4

Related Questions