当我尝试通过AngularFireList中的对象之一寻找对象时,无法获得对象(贷款)。你有什么建议?
组件但是,它没有给我任何回报。
this.prestamoService.obtenerPrestamo("P34520181127")
.snapshotChanges()
.subscribe(item => {
this.prestamoLista = [];
item.forEach(element =>{
let x = element.payload.toJSON();
x["$key"] = element.key;
this.prestamoLista.push(x as Prestamo);
});
});
服务
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) {}
obtenerPrestamo(codigo: string)
{
return this.prestamoLista = this.firebase.list('prestamos', ref =>ref.orderByChild('codigo').equalTo(codigo));
}
}
我需要从我的'obtenerPrestamo()'方法获得一笔特定的贷款,该方法应该搜索贷款属性。