Reputation: 49
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?
Upvotes: 0
Views: 55
Reputation: 31105
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.
Upvotes: 2