0

So basically, i have a ionic mobile application that retrieves data from Firebase.

this is the code for html that displays data which comes from travalList$ that is an observable.

  <ion-list *ngFor="let item of travelList$ | async">
<ion-card (click)="itemTapped($event, item)" *ngIf="item.userId != currentUserId">
  <ion-card-header>
    <h4><b>{{item.firstname}} {{item.lastname}} ({{item.email}})</b></h4>
  </ion-card-header>
  <ion-card-content>
    <h5>{{item.fromAddress}}</h5>
    <p>at {{item.fromDate}}</p>
    <h6>To</h6>
    <h5>{{item.toAddress}}</h5>
    <p>at {{item.toDate}} </p>
  </ion-card-content>
</ion-card>

code for initializing items to be displayed. this is called at the constructor,so the getTravelList() retrieves data from firebase.

   initializeItems(){
this.travelList$ = this.plsdala.getTravelList()
.snapshotChanges()
.map(
  changes => {
    return changes.map(c=>({
      key: c.payload.key, ...c.payload.val()
    })).slice().reverse();
    console.log(this.travelList$); //to reverse order
  });

}

i wanted to put the retrieved data in an array but how do i wait the observable? i need the array for search function.

Aref Zamani
  • 2,023
  • 2
  • 20
  • 40
Jennica
  • 327
  • 1
  • 3
  • 15
  • Why exactly do you need 'to put the retrieved data in an array'? This is already handled with async pipe. – Estus Flask Feb 04 '18 at 11:56
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Estus Flask Feb 04 '18 at 11:56
  • hi estus, the initilize function was coded by my friend. can you explain it to me? i need to push the element in an array cause ill make a search featurer pleasee. ive been trying to understand for hours already :(( – Jennica Feb 04 '18 at 15:27
  • Duplicate question is general and covers observables, too. You need something like `this.travelList$.subscribe(list => { this.travelList = list })` – Estus Flask Feb 04 '18 at 15:30
  • can you structure it for me? i already read the doumentation and im having a hard time hehe sorry – Jennica Feb 04 '18 at 15:38
  • Just add it to initializeItems. I'm not sure if this will work for you, because the question doesn't contain http://stackoverflow.com/help/mcve and it's unknown how search feature works. – Estus Flask Feb 04 '18 at 16:18

0 Answers0