2

I have a Firebase firestore collection and I can retrieve data from it using the construct

db.collection('myCollection').get().then(res => ...)

That works fine, it returns data.
But I use a @angular/material table and that component expects to retrieve an Observable from the datasource. Currently the table is not displaying anything and I suspect it is because Firestore returns a Promise instead of Observable. How can I convert the Promise to an Observable?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Marc
  • 401
  • 1
  • 5
  • 15
  • Does this answer your question? [Convert Promise to Observable](https://stackoverflow.com/questions/39319279/convert-promise-to-observable) – jonrsharpe Mar 14 '20 at 08:15

2 Answers2

2

Easy... this can be accomplished using the from rxjs operator:

import {from} from 'rxjs'; 
from(<Promise>).subscribe(res => ...)

will return the Promise as an Observable.

Marc
  • 401
  • 1
  • 5
  • 15
0

Alternatively you can use AngularFire2, which makes this (and more more) mapping for you.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807