How to get a table from JSON data in Angular 2

advertisements

I am developing an app in angular 2. I have created a service, now i want to get specific array from json data how i can get.

i have service code like this

getProjects(): Promise<Project>{
return this.getData()
  .toPromise()
  .then(response => response.json())
  .catch((error: string) => console.log(error));
}

this is returning all the json data but i want only "Projects" array to be fetched from json.

JSON code

{
   "features":[],
   "posts":{},
   "Projects":[
    {
        "id":"proj-1",
        "name":"Design for creative",
        "meta":{
            "date":"03 November, 2016",
            "url":"http://www.pixelsocket.com",
            "skills":[
                "ui design",
                "programming",
                "marketing"
            ]
        },
        "images":[
            "assets/images/design-creative-01.jpg",
            "assets/images/design-creative-02.jpg",
            "assets/images/design-creative-03.jpg",
            "assets/images/design-creative-04.jpg"
        ],
        ...
}

update

getProject(id: string): Promise<Project>{
 const url = `${this.getProjects()}/${id}`; // can i call getProjects() method here

 return this.http.get(url)
   .toPromise()
   .then(response => response.json())
   .catch((error: string) => console.log(error));
}


getProjects(): Promise<Project>{
return this.getData()
  .toPromise()
  .then(response => response.json().projects) // <<< added .projects
  .catch((error: string) => console.log(error));
}

getProject(id: string): Promise<Project>{
  return this.getProjects()
  .then(p => `${p}/${id}`) // no idea where `id` should come from
  .then(url => {
    return this.http.get(url)
   .toPromise()
   .then(response => response.json())
   .catch((error: string) => console.log(error));
  })
}