在 Angular 16 中从 firebase 获取产品列表时出现问题

问题描述 投票:0回答:1
angular typescript firebase angularfire
1个回答
0
投票

数据库中似乎没有

product
键,而只有
products 
键。因此将
getAll()
方法更改为以下内容:

  getAll() {
    return this.db.list('/products ').snapshotChanges();
    .pipe(map( action => action
      .map(a => {
        const key = a.payload.key;
        const data = a.payload.val();
        return  data;
      }))); 
  }

然后在模板中执行以下操作:

 <tbody>
        <tr *ngFor="let p of products$| async">
            <td>{{ p.title }}</td>
            <td>{{ p.price }}</td>
            <td>
                <a [routerLink]="['/admin/products/', p.key]">Edit</a>
            </td>
        </tr>
    </tbody>
© www.soinside.com 2019 - 2024. All rights reserved.