Rajiv Krishnaa
Rajiv Krishnaa

Reputation: 99

Bind JSON object array to View in Angular2 nativescript

I have a JSON object returned from my API like this

{
"ID": "GM5VY",
"Passengers": [
 {
"Firstname": "TEST",
"Lastname": "TRAVELLER",
"TotalCount": "1",
FqtT": [
  {
    "MembershipID": "XXXXXX"
  }
],
"Errors": null,
"Information": null,
"Warnings": null
}
],
"Errors": null,
"Information": null,
"Warnings": null
}

I'm converting this Object to an array using Pipe filter and trying to display Passengers First Name in View. But I couldn't able to retrieve

<StackLayout *ngFor=" let passengerls of PassengerDetails | objtoarray; let i = index">
    <Label [text]="passengerls?.value?.Passengers ? passengerls?.value?.Passengers[i].Firstname:null"> </Label>                        

</StackLayout>

Please help me in acheiving this!!!

Upvotes: 2

Views: 426

Answers (1)

Eddy Verbruggen
Eddy Verbruggen

Reputation: 3550

How about using a simpler way to iterate the array:

<StackLayout *ngFor="let passenger of PassengerDetails.Passengers">
  <Label [text]="passenger.Firstname"></Label>
</StackLayout>

Upvotes: 2

Related Questions