0

Here's my object inside EntryList variable in my component

{
    "id": 0, 
    "startAddress": {
       "id": 6,
       "addressString": "addressString"
    },
    "endAddress": {
       "id": 6,
       "addressString": "addressString"
    },
    "distanceInKm": 5.637376656633329,
    "travelTime": "travelTime",
    "standingTime": "standingTime",
    "vehicle": {
       "id": 2,
       "licensePlateNumber": "licensePlateNumber"
    },
    "driver": {
       "id": 7,
       "name": "name"
    }
}

I want to display columns: driverName, vehicleName, startAdrress, endAdress, distanceInKm, travelTime, standingTime.

I tried using <tr *ngFor="let DLBlist of EntryList"> but there's no display.

3
  • NgFor is for arrays only, and your data is an object. You’ll need to restructure your data first Commented Apr 2, 2021 at 8:11
  • how can i do that? Commented Apr 2, 2021 at 8:16
  • EntryList.startAddress.id Commented Apr 2, 2021 at 8:31

1 Answer 1

1

Those are nested elements. You can access them with the following code

DLBlist?.driver?.name
DLBlist?.startAddress?.addressString
DLBlist?.endAddress?.addressString

?. is the safe access operator, so if they don't exist no error is thrown

Sign up to request clarification or add additional context in comments.

Comments

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.