0

I'm not able to get an object when I try to look for it through one of its attributes in an AngularFireList. What do you suggest?

Table Structure on FB

Service

import { Injectable } from '@angular/core';

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

import { Prestamo } from '../models/prestamo';
import { FirebaseDatabase } from 'angularfire2';

@Injectable({
  providedIn: 'root'
})
export class PrestamoService {

  prestamoLista: AngularFireList<any>;
  prestamoSeleccionado: Prestamo = new Prestamo();

  constructor(private firebase: AngularFireDatabase) {}

  obtenerPrestamos()
  {
    return this.prestamoLista = this.firebase.list('prestamos');
  }

  obtenerPrestamo(codigo: string)
  {
    return this.prestamoLista = this.firebase.list('prestamos', ref => ref.orderByChild('codigo').equalTo(codigo));
  }
}

1 Answer 1

1

Just return the snapshotChanges list from the service,

  obtenerPrestamos()
  {
    return this.firebase.list('prestamos').snapshotChanges();
  }

From component subscribe to the observable

this.yourService.obtenerPrestamos().subscribe((data) => {
   console.log(data)
})
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer @SachilaRanawaka ! But my problem is on the method obtenerPrestamo(codigo: string) , which it searchs through code atribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.