Ionic 3 queries using Angularfire2

Asked

Viewed 583 times

0

I’m trying to perform a search with Ionic 3 + Angularfire2. I have a list of all the data from firebase, but I can’t filter this data, it does not return me anything.

ts.

import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';

dashboardData: FirebaseListObservable<any>;

constructor(private afDatabase:     AngularFireDatabase) {

  this.dashboardData = this.afDatabase.list('/motoristas');
}

getRota(rota: string){
this.dashboardData = this.afDatabase.list('motoristas', {
  query: {
    orderByChild: 'rota',
    equalTo: rota
  }
});
}

file . html

<ion-list>
    <ion-item>
        <ion-label>Rota</ion-label>
        <ion-select [(ngModel)]="rota" (ionChange)="getRota(rota)">
            <ion-option value="Caruaru">Caruaru</ion-option>
            <ion-option value="Belo Jardim">Belo Jardim</ion-option>
        </ion-select>
    </ion-item>
</ion-list>

<ion-list>
    <ion-item *ngFor="let motorista of dashboardData | async" (click)="showOptions(country.$key, country.nomeMotorista)">

        <ion-thumbnail item-start>
            <img src="./assets/img/icon.svg">
        </ion-thumbnail>
        <h2>{{ motorista.nomeMotorista }}</h2>
        <p> {{ motorista.rota }} </p>
        <button ion-button clear item-end color="outro"> <ion-icon ios="ios-people" md="md-people"> {{ motorista.numPassageiros }} </ion-icon></button>
    </ion-item>
</ion-list>

I have no return.

inserir a descrição da imagem aqui

1 answer

0

Hello, Friend could show you how this your bank:

'Cause that’s how I search:

 private PATH = 'produtos/'
...

get (key: string ){
return this.db.list(this.PATH, ref => ref.orderByChild('codigo').equalTo(key))
  .snapshotChanges()
  .map (Changes => {
    return Changes.map(p => ({
       key: p.payload.key, ...p.payload.val()}));
    })
  } 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.