当我尝试通过AngularFireList中的属性之一寻找对象时,我无法获得该对象。你有什么建议?
服务
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));
}
}
答案 0 :(得分:0)
只需从服务中返回TreeSet
列表,
snapshotChanges
从组件订阅可观察对象
obtenerPrestamos()
{
return this.firebase.list('prestamos').snapshotChanges();
}