I'm trying to get  posts from a wordpress  site to output to a view. 
I  want to iterate through the posts in AppComponent with a forEach and 
then capture it in the view with a ngFor key of keys.   Should be simple 
except parsing the JSON object is killing me.  
First problem is some of the fields have nested objects.  TIA

   1. posts:Array(905)
      1. 0:{ID: 8239, site_ID: 20683037, author: {…}, date: 
      "2017-12-08T14:00:04-08:00", modified: "2017-12-08T14:00:04-08:00", …}
      2. 1:{ID: 7827, site_ID: 20683037, author: {…}, date: 
      "2017-12-08T12:00:44-08:00", modified: "2017-10-10T14:08:53-07:00", …}
      3. 2:{ID: 7825, site_ID: 20683037, author: {…}, date: 
      "2017-12-07T12:00:06-08:00", modified: "2017-10-10T14:08:15-07:00", …}
      4. 3:{ID: 7823, site_ID: 20683037, author: {…}, date: 
      "2017-12-06T12:00:43-08:00", modified: "2017-10-10T14:06:55-07:00", …}
      5. ....
      
But even without the nested objects, I can't figure out how to access the 
first level, other than one field at a time instead of one row at a time. 
Reason being the json object is called posts, so I couldn't write an 
interface directly for the fields,without prefixing it with posts and the 
interface didn't work that way
   What I have below is the fields in 1 row, instead of the 905  rows of 
data.  And I couldn't get the forEach and the map to work.  TIA
-------------------------------

export class AppComponent implements OnInit {

results = '';
results : string[];
  constructor(private http: HttpClient) {}
  
  ngOnInit(): void {
  
this.http.get('https://public-api.wordpress.com/rest/v1.1/sites/idcdistro.wordpress.com/posts/?author=ajpRspthis&number=10&pretty=true')
//.map(res => res.json())
  .subscribe(data => {
  console.log(data);
console.log("ID " + data['posts'][0].ID);
console.log("URL " + data['posts'][0].URL);
console.log("site_ID " + data['posts'][0].site_ID); 
    console.log("Capabilities " + data['posts'].categories);//content, date
    console.log("Author " + data['posts'].author); //name 
    console.log("Discussion " + data['posts'].discussion);//exerpt, 
like_count
    console.log("Modified " + data['posts'].modified);
    console.log("Other URLs"+ data['posts'].other_URLs);//short_URL, 
site_ID, slug, status, sticky
    console.log("Tags "+ data['posts'].tags);//Christmas, Concerts, Holiday 
Jam, Narada Michael Walden,Narada Michael Walden Foundation
    console.log("Terms "+ data['posts'].terms);
    console.log("Title "+ data['posts'].title);
    console.log("Type "+ data['posts'].type);
    
   // this.posts.forEach(d => console.log(d.ID,d.URL,d.site_ID));
   });
  }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to