Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
How to convert an Observable stream into an Observable Array

I am trying to retrieve a list of dogs from a database. I want to retrieve the list of dogs as an Observable<Dog[]>. However when I call toArray() or use any other method to try convert the incoming stream to an array I either receive no data when calling the retrieveDogs(dogsId) method. How does one go about retrieving an Observable array instead of just an Observable stream?

    retrieveDogs(dogIds : Array<string>): Observable<Dog[]>{
        return Observable.from(dogIds)
                .map(dogId => this.retrieveDog(dogId)) 
                .flatMap(dogObservable => dogObservable)
                .toArray();
     }

    retrieveDog(dogId : string) : Observable<DogEntity> {
     //afDB -> AngularFireDatabase that returns an observable with the data from the firebase database
        return this.afDB.object(DB_DOGS + DB_DASH + dogId)
                .map(dogObject =>DogEntity.convertObject(dogId,dogObject)
    }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You could do that to retrieve your data:

retrieveDogs(dogIds : Array<string>): Observable<Dog[]>{
  let obs = dogIds.map(dogId => this.retrieveDog(dogId));

  return Observable.forkJoin(obs);
}

retrieveDog(dogId : string) : Observable<DogEntity> {
  return this.afDB.object(DB_DOGS + DB_DASH + dogId)
    .map(dogObject => DogEntity.convertObject(dogId,dogObject));
}

Simple demo here http://jsbin.com/sotunopocu/2/edit?js,console

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda