Angular: 如何为关联数组做 *ngFor

Angular: how to do *ngFor for associative array

dataJSON(数组) dataList.const.ts https://codebeautify.org/jsonviewer/cb28b09d

component.html

//第一个*ngFor(工作 {{item.city.id}} {{item.city.name}} {{item.city.coord.lon}} {{item.city.coord.lat}} {{item.city.country}} {{item.city.population}}

//第二个*ngFor(无法显示)

<tr *ngFor="let item of list">
        <td>
      {{item.list_}}
        </td>
        <td>
      {{item.list_.temp.day}} °C
        </td>
        <td>
      {{item.list_.temp.min}} °C
        </td>
        <td>
      {{item.list_.temp.max  }} °C
        </td>
        <td>
      {{item.list_.temp.night  }} °C
        </td>
        <td>
      {{item.list_.temp.eve  }} °C
        </td>
        <td>
      {{item.list_.temp.morn  }} °C
        </td>
        <td>
      {{item.list_.pressure}} hpa
        </td>
        <td>
      {{item.list_.humidity}} %
        </td>
        <td>
              {{item.list_.weather.id }}
        </td>
        <td>
      {{item.list_.weather.main }}
        </td>
        <td >
      {{item.list_.weather.description }}
        </td>
        <td>
      {{item.list_.weather.icon }}
        </td>
        <td>
      {{item.list_.speed}} meter/sec
        </td>
        <td>
      {{item.list_.deg}} °
        </td>
        <td>
      {{item.list_.clouds}} %
        </td>
        <td>
              {{item.list_.rain}}
        </td>
    </tr>

你可能想看看这个:

基本上你应该这样写:

*ngFor = "let item of list"

然后

*ngFor = "let l of item.list_"

然后使用

<td>{{l.temp.night}}</td>

https://stackblitz.com/edit/ngfor-example-pnuhfh

这是根据您的反馈评论为您的答案提供的 stackblitz 示例。

相关代码片段为:

<tr *ngFor = "let item of fetchData">
  <td *ngFor = "let l of item.list_">
    {{l.dt}}|
    {{l.temp.night}}|
  </td>
</tr>