Keno Eduave
Keno Eduave

Reputation: 11

Display object inside object in angular

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.

Upvotes: 0

Views: 119

Answers (1)

Panagiotis Bougioukos
Panagiotis Bougioukos

Reputation: 18959

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

Upvotes: 1

Related Questions