2

I have an array of JSON objects named 'books', however I can't seem to extract any of the information for use in the HTML.

The array is in the form :

Console log of array form

Each object is in the form:

Form of JSON object

I am trying to access fields such as isbn13 from the HTML file. As follows:

<ion-content>
  <ion-item *ngFor="let book of books">
    {{book.data.isbn13}}
  </ion-item>
</ion-content>

This code throws no error but displays no text. If I reduce it to {{book.data}} it prints [object Object] for each entry in the array.

How can I access isbn13?

4
  • i think theres a typo. In your *ngFor you are trying to display isb13 and not isbn13. Commented Feb 21, 2017 at 14:32
  • Adding to @AakashThakur comment, the path seems to be book.data[0].isbn13. Commented Feb 21, 2017 at 14:34
  • Thank you everybody! Indeed data[0] was the problem! Commented Feb 21, 2017 at 14:40
  • @AakashThakur What is the recommended method to use for deleting a specific object from the array> Commented Feb 21, 2017 at 15:42

1 Answer 1

3

You've made a mistake. Data is and array, not an object. So you need to access the first element of array.

<ion-content>
   <ion-item *ngFor="let book of books">
     {{book.data[0].isbn13}}
   </ion-item>
</ion-content>
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, I'm not sure how that mistake arrived, it must have been while copying in to the question. {{book.data.isbn13}} still gives no output.
Nice edit dude. Read the above comments in time. haha.
Perfect! It is working now, I will accept the answer ad soon as the time limit allows me to. Thanks!

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.