angular 4 ngfor 具有 id 值的父键

angular 4 ngfor parent key with id values

我想从 UserHardware 接收所有父键的所有值 随机生成的密钥中的子节点具有结构:name: Test,desc: test

我在构造函数(组件)中的代码

 this.userHardwareList = db.list('UserHardware/');
this.items = this.userHardwareList.snapshotChanges().map(changes => {
  return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});

在(模板)

 <li *ngFor="let item of items | async">
 {{item.key}}
</li>

现在我只收到值 udwcGxqx50ZtoF8EABoFh8GVet2 (UID) 但我也想要这个 UID 中的值。

我试过:{{item.name}} 但我什么也没显示。

然而,当我更改构造函数中的代码时:

this.userHardwareList = db.list('UserHardware/udwcGxqx50ZtoF8EABoFh8GVet2');

它有效,我可以使用

获取值和不同的生成键
{{item.name}}` {{item.key}}` {{item.desc}}`

不指定UID如何实现?

我怀疑你想做

 this.userHardwareList = db.list('UserHardware/');
this.items = this.userHardwareList.snapshotChanges().map(changes => {
  return changes.map(c => ({ key: c.payload.key, data:c.payload.val() }));
});

然后

<li *ngFor="let item of items | async">
 {{item.key}}
  <ol>
    <li *ngFor="let data of items">
      {{data.name}}{{data.desc}}
    </li>
  <ol>
</li>