0

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

component.html

//1st *ngFor (worked <tr *ngFor="let item of list"> {{item.city.id}} {{item.city.name}} {{item.city.coord.lon}} {{item.city.coord.lat}} {{item.city.country}} {{item.city.population}}

enter image description here

//2nd *ngFor (cannot display)

<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>

3

imxitiz
  • 3,920
  • 3
  • 9
  • 33
seekerJackson
  • 41
  • 1
  • 9

1 Answers1

1

You may want to take a look into this: ngFor inside ngFor

Basically you should write something like this:

*ngFor = "let item of list"

And then

*ngFor = "let l of item.list_"

Then use

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

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

This is a stackblitz example for your answer, based on your feedback comments.

The relevant code snippet is:

<tr *ngFor = "let item of fetchData">
  <td *ngFor = "let l of item.list_">
    {{l.dt}}|
    {{l.temp.night}}|
  </td>
</tr>
Soumya Kanti
  • 1,429
  • 1
  • 17
  • 28
  • mate I tried to be : (unfortunately its not worked) ` {{l.temp.night}} ` – seekerJackson Jan 04 '19 at 08:29
  • Yes. Is your problem is how to fit that in a table? – Soumya Kanti Jan 04 '19 at 08:35
  • yeah thats my question : how to fit that in a table? T_T – seekerJackson Jan 04 '19 at 08:40
  • Then this is probably the answer you are looking for: https://stackoverflow.com/questions/40860933/ngif-and-ngfor-on-td-td-element – Soumya Kanti Jan 04 '19 at 08:42
  • See I have updated my answer with an example. I did not use `ng-container`. – Soumya Kanti Jan 04 '19 at 08:47
  • thanks mate I tried both solution and still cannot display the data – seekerJackson Jan 04 '19 at 08:57
  • oh man you're a very nice guy. tq but still have problemT_T let me show you the console.error https://imgur.com/a/WUYxoOW – seekerJackson Jan 04 '19 at 09:15
  • Is it `l` in `{{l.temp.night}}`? From the screenshot, it looks like `1` (one). – Soumya Kanti Jan 04 '19 at 09:32
  • bro u r the best. list_dt can display now but list_.temp.night cannot – seekerJackson Jan 04 '19 at 09:44
  • Thanks dear. Now I am at my wit's end; if list_.dt can be displayed, then so will list_.temp.night, given that your data has the fields. Can you try `{{l.temp?.night}}` and `{{l?.temp.night}}`? Don't mess `l` with `1`. – Soumya Kanti Jan 04 '19 at 10:03
  • bro @SoumyaKanti ive got another angular practice now. my Q now : how to upgrade the code from angular js to angular 7. Here is my exercise: jsbin.com/gumaraz/edit?html,output Any idea? – seekerJackson Jan 10 '19 at 07:07
  • I think that is completely different question. You may do some google - I have no experience in such migration. If the search does not help, consider logging a new question in Stackoverflow. – Soumya Kanti Jan 10 '19 at 07:28
  • okay bro~may i ask u why the manager deleted my post which i have written my ans – seekerJackson Jan 10 '19 at 07:50
  • I think it was a screenshot rather than text. The community standard is to contain everything / as much as possible within stackoverflow itself. – Soumya Kanti Jan 10 '19 at 07:52
  • so sad that i changed to text and they still deleted it , well is okay i just want to help ppl who hv the same problem – seekerJackson Jan 10 '19 at 07:55
  • Yes, sometimes this is weird, some folks become overactive and think stackoverflow as their personal property and take it personally. I too faced such behaviors in the past. Despite that, it is still a nice platform to seek help and learn. – Soumya Kanti Jan 10 '19 at 08:40