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

219
Vistas
Filtering with multiple fields in firebase realtime database and angularfire

Due to the limitation of firebase realtime database to filter on multiple fields i am trying to filter the data on client side. I have declared a variable which matches with a field in the result set. But i am unable to refresh the results while changing the field. I know there is something wrong with the way i am filtering the data. Could someone please someone show some paths to achieve this.

Typescript:

import { Component, OnInit } from '@angular/core';
import { AngularFireDatabase } from '@angular/fire/compat/database';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Item } from '../models/item';

@Component({
    selector: 'test-component',
    templateUrl: './test-component.html',
    styleUrls: ['./test-component.scss']
  })

export TestComponent implements OnInit {

    itemRef: Observable <Item[]> = new Observable();
    group_id: number = 5; //dynamic
    currentTypeSelected: number = 2; //dynamic
    currentTypeBehaviorSubject: BehaviorSubject<number> = new BehaviorSubject<number>(2);

    constructor(
        private _db: AngularFireDatabase,
    ){ }

    ngOnInit(): void {
        this.itemRef = this._db.list('/items', ref => ref.orderByChild('group_id').equalTo(this.group_id)).snapshotChanges().pipe(
            map(action => action.map(a => {
                const obj = a.payload.val();
                return new Item(obj);
            }).filter(item => item.type == this.currentTypeSelected))
        )
    }
}

Template:

<div *ngFor="let item of itemRef | async">
  <pre>{{ item | json}}</pre>
</div>

Update: I was able to solve this issue by the following code. Not sure if this is the proper method to solve this.

this.itemRef = combineLatest([this._db.list('/items', ref => ref.orderByChild('group_id').equalTo(this.group_id)).snapshotChanges(), this.itemType.asObservable()]).pipe(
                map(results => results[1].map(a => {
                  const obj = a.payload.val();
                  return new Item(obj);
                  }).filter(item=>item.type==results[0])
                )
              );
about 4 years ago · Juan Pablo Isaza
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