0

Here is my code snippet: I know I am getting a result from my webservice because it is returning a 200 ok. but I cannot loop through to pull the data elements out.

this.cityService.searchByRegion(formData)
        .subscribe((resultsReturned) => {

            console.log("ResultsReturned :" + resultsReturned);
            resultsReturned.forEach((city) => {
              var newSearchResult = new SearchResult(city);
              this.results.push(newSearchResult);
            });

Here is the JSON returned:

[ {
  "region_id" : "8",
  "time" : "2015-01-16T08:31:40",
  "bus_count" : "200",
  "speed" : "15.68",
  "number_of_reads" : "3412"
}
, {
  "region_id" : "8",
  "time" : "2015-01-15T08:31:39",
  "bus_count" : "200",
  "speed" : "15.68",
  "number_of_reads" : "3535"
}
, {
  "region_id" : "8",
  "time" : "2015-01-14T08:40:47",
  "bus_count" : "200",
  "speed" : "14.32",
  "number_of_reads" : "3463"
}]

How do I return my JSON data parsed out, using the forEach? I tried returnResults.json ... but that just returned a buth of object:object

I am pretty new to Angular2, so any help would be appreciated.

Ankit Singh
  • 24,525
  • 11
  • 66
  • 89
Paul T. Rykiel
  • 1,177
  • 6
  • 26
  • 48

0 Answers0