Angular Firebase - Cloud Firestore and AsyncPipe

192 views
Skip to first unread message

Jamison Roberts

unread,
Jun 4, 2019, 9:46:07 AM6/4/19
to Firebase Google Group
I use async pipe to display the observable returned by snapshotChanges().  If in the setup / binding of the observable (ngOnInit for instance) I pipe the finalize operator, it seems to never be called.  Is this expected ( I think so from what I've read ), and is the only recourse to handle the subscription myself and forego using asyncPipe?

Thanks,
-Jamison

Jamison Roberts

unread,
Jun 6, 2019, 11:43:53 PM6/6/19
to Firebase Google Group
I have since learned that cloud firestore observables never complete so you cannot use finalize by itself. In my case I was able to also use take (1) which will auto complete the observable, then finalize works as expected.

Jeremy Sistrunk

unread,
Jun 7, 2019, 10:55:55 AM6/7/19
to fireba...@googlegroups.com
Yea, you can do that, but you have to ask yourself, if you are just trying to see what is inside, do you really wanna use snapshotChanges() or the simpler valueChanges(), if you use snapshotChanges, wherever property you are assigning the observable to, you need to pipe, then map the values so that the data property is the one that is returned from the array of values that is extracted from the server, you can then either keep it as an array and display it using ngFor, or you can break that further down by using reduce() 

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/8b0ae391-0934-4379-8385-61cfb3e7b562%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages