0

I am trying to pass data from a json feed to the html file, the below is not working.

app.component.html

<ul *ngFor="let unit of units">
  <li>
    {{unit.details.count}} // getting data OK result -> 5642
  </li>
  <li>
    {{unit.cars.vehicle_id}} // not getting data
  </li>
</ul>

units_feed.json

[{"details":{"count":"5642"},"cars":[{"vehicle_id":"2056437754"},{"vehicle_id":"2056437753"},{"vehicle_id":"2056356347"},{"vehicle_id":"2056437752"},{"vehicle_id":"2056395634"}]}]

1 Answer 1

1

You cant access it as unit.cars is an array of object. If You wanted to access one of those objects i.e. ones with the vehicle_id you could use {{unit.cars[0].vehicle_id}}. Notice the [0] that telling it to access the first item in the array and the you can view its property vehicle_id.

Would guess you would have to do something like this

<ul *ngFor="let unit of units">
  <li>
    {{unit.details.count}} 
  </li>
  <li *ngFor="let car of unit.cars">{{car.vehicle_id}}</li>
</ul>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, well explained.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.