I have this angular2 code:
af.database.list('/users').subscribe(
value=>console.log(value),
error=>console.log(error),
()=>console.log("FIMISHED!!!") //Never gets here
);
Problems:
Questions:
Hey @stavalfi, I'll be happy to answer your questions!
Complete will not fire unless you manually terminate the Firebase listener. You can do this by calling dispose on the observable, using an operator that disposes, or calling .off() on the reference yourself.
If you're looking to convert to a promise, then I recommend using take:
af.database.list('users').take(1).toPromise();
Hi @davideast thanks for answering so fast!
Thanks very much!!!!
Hello @stavalfi ,
I have the similar issue as you, and how did you solve your issue ?
af.database.list('/users').subscribe(
value=>console.log(value),
error=>console.log(error),
()=>this.loading = false //Never gets here
);
Hi @johnqiuwan ! As @davideast answered, firebase observable will never be completed because it is a real time database and things are changes over time so if you ask for users as u did, u dont ask for them, you subsribe to changes in the users so every time a new user created, this line will be called : console.log(value). If you want to force the observable to finish after you got the first value, do that: someObservalbe.take(1).doSomethingElseLike_toPromise().then(...).
Most helpful comment
Hi @johnqiuwan ! As @davideast answered, firebase observable will never be completed because it is a real time database and things are changes over time so if you ask for users as u did, u dont ask for them, you subsribe to changes in the users so every time a new user created, this line will be called : console.log(value). If you want to force the observable to finish after you got the first value, do that: someObservalbe.take(1).doSomethingElseLike_toPromise().then(...).