Reputation: 92
Disclaimer: I am new to Angular :-)
I am experimenting with intertwining Angular and a weather api and I am stumped on how to approach displaying nested data in the JSON payload (Namely, the items under the Historical object). I am able to call and display top level items in the payload.
Here's where I am at:
{{ this.weatherData?.current.precip }} <-- this shows the current precipitation successfully
{{ this.weatherData?.historical.maxtemp }} <--- this doesn't display anything
API documentation: https://weatherstack.com/documentation
Many thanks for your coaching and patience that comes with a curious newbie.
Upvotes: 1
Views: 69
Reputation: 2253
The historical data is returned by date, so you would have to do like this to show a single date:
{{ this.weatherData?.historical['2018-08-30'].maxtemp }}
Or in a loop to show all dates:
<div *ngFor="let history of this.weatherData?.historical | keyvalue">
{{ history.key + ': ' + history.value.maxtemp }}
</div>
Upvotes: 1
Reputation: 2732
The this.weatherData?.historical
is an array with key is as Date. If you are certain that there will only be 1 value in this.weatherData?.historical
array, you should be able to access it like below:
this.weatherData?.historical[0].maxtemp
Upvotes: 0