5

I have a json array like following;

"collectings": [
    {
      "hint": "OPEN",
      "amount": 24
    },
    {
      "hint": "CREDIT CARD",
      "amount": 347
    },
    {
      "hint": "CASH",
      "amount": 256.5
    }
  ]

Now, I want to display this data on a list dynamically, I am trying to do it like following;

<ion-content>
<div class="row" *ngIf="collectings && collectings.length > 0">
  <ion-list>
    <ion-list-header>Comedy</ion-list-header>
    <ion-item *ngFor="let collecting of collectings">{{collectings}}</ion-item>
  </ion-list>
</div>
</ion-content>

but, it is displayed on the page like the below image; enter image description here How can I display it properly?

1 Answer 1

3

Instead of {{ collectings }} (which is the array)

<ion-item *ngFor="let collecting of collectings">{{collectings}}</ion-item>

you should print the collecting property (without the ending s) and use the hint or amount sub-properties like this:

 <ion-item *ngFor="let collecting of collectings">
   {{collecting.hint}} - {{ collecting.amount }}
 </ion-item>
Sign up to request clarification or add additional context in comments.

2 Comments

@sebaferreas I have already tried it but, when I do that it displays nothing. I have already checked the array is empty or not with the ngIf part because, I am getting array as response from rest and bind it to my array.
@sebaferreas yeah you are right. I was printing the collectings. Now, its working

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.