0

I'm trying to return the data I get from a query with firease using Ionic and Angular, but the array returns 'undefined'

  QueryList (id: string ) {    

    this.db.collection('/list', ref => ref.where('id', '==', id)).valueChanges().subscribe(ref => {return ref});

  }

What would be the correct syntax to return the array?

1 Answers1

2

Return the observable and subscribe where the data is needed

QueryList (id: string ): Observable<any> {    
  return this.db.collection('/list', ref => ref.where('id', '==', id)).valueChanges();
}

Component

ngOnInit() {
  this.someService.QueryList(id).subscribe(ref => {this.ref = ref});
}

The data is asynchronous and it isn't possible to return the value synchronously.

More details on how to access asynchronous data here.

ruth
  • 29,535
  • 4
  • 30
  • 57