【问题标题】:Problem to get an item from an AngularFireList从 AngularFireList 获取项目的问题
【发布时间】:2018-12-19 16:17:10
【问题描述】:

当我尝试通过 AngularFireList 中的某个属性来查找对象时,我无法获取它。你有什么建议?

Firebase Table Structure

服务

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));
  }
}

【问题讨论】:

标签: angular typescript firebase firebase-realtime-database


【解决方案1】:

您可能正在使用 valueChanges 来解决此问题:

.snapshotChanges()
  .pipe(map(items => {
    return items.map(a => {
      const data = a.payload.val();
      const key = a.payload.key;
      return {key, ..data};   
    });

那么你就可以订阅这个了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    相关资源
    最近更新 更多