Fetch data from nested json


#1

Hi,

my json is like this, and it always returns one record

{“records”:[{“ID”:“1012”,“IMAGES”:“1012a.jpg”,“CONTENT”:“content1002”,“TITLE”:“title1002”}]}

how can i fetch the data without using the *ngFor?

ts file

      this.link = 'http://xxxx.com/apps/data2.php?action=get_posts&id='+this.id;

    //  alert(this.link);

      this.http.get(this.link).map(res => res.json()).subscribe(data => {
          this.post = data.records;
      });

thanks


#2

Sorry could you elaborate the problem a little more? Cant understand what you exactly need.


#3

thanks for the reply!

my question is when i fetch the data using {{post.ID}} in home.html

i got error

Runtime Error
Uncaught (in promise): TypeError: Cannot read property ‘ID’ of undefined TypeError: Cannot read property ‘ID’ of undefined at Object.eval [as updateRenderer]


#4

in your homePage be sure to initialise your post = {}. Then it will get populated after the async operation is done.

Check this thread we had a similar discussion here.


#5

yeah! got it , thanks a lot !!!