Here is the URL, which in the browser renders as JSON:
Here is what I tried to store the data in a variable:
$http.get('http://api.geosvc.com/rest/US/84606/nearby?apikey=4ff687893a7b468cb520b3c4e967c4da&d=20&pt=PostalCode&format=json').then(function(response) {
$scope.zipCodes = response;
});
Here is the HTML where I tried to display it:
<pre>zipCodes {{zipCodes | json}}</pre>
But nothing displays, any idea what I'm doing wrong?
I also tried this:
$http.jsonp('http://api.geosvc.com/rest/US/84606/nearby?apikey=4ff687893a7b468cb520b3c4e967c4da&d=20&pt=PostalCode&format=json').then(function(response) {
$scope.zipCodes = response;
});
I've also tried AngularJS resource but that is also returning undefined:
var zipCodes = $resource("http://api.geosvc.com/rest/US/84606/nearby?apikey=4ff687893a7b468cb520b3c4e967c4da&d=20&pt=PostalCode&format=json",
{ callback: "JSON_CALLBACK" },
{ get: { method: "JSONP" }}
);
zipCodes.get({}, function(zipCode){
console.debug(zipCode.PostalCode);
});
console.debug(zipCodes.get());
$scope.zipCodes = zipCodes.get().results;
$scope.zipCodes = response;
should be changed to$scope.zipCodes = response.data;
– Pankaj Parkar May 7 '15 at 22:22