问题从AngularFireList返回值

时间:2018-12-14 14:01:48

标签: angular firebase firebase-realtime-database

当我尝试通过AngularFireList中的属性之一寻找对象时,我无法获得该对象。你有什么建议?

Table Structure on FB

服务

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 个答案:

答案 0 :(得分:0)

只需从服务中返回TreeSet列表,

snapshotChanges

从组件订阅可观察对象

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