Reputation: 311
I have gone through a few posts and I am still having trouble accessing nested object data. I am using a factory to fetch weather info using jsonp:
this.testApi = function(coords) {
var deferred = $q.defer();
$http.jsonp(API_ROOTS + '?key=khjsgf7bhv3y3hy776763&q=' + coords.latitude + ',' + coords.longitude + '&cc=yes&includeLocation=yes&format=json&callback=JSON_CALLBACK')
.then(function(response) {
deferred.resolve(response.data);
console.log(response.data.data);
}, function(error) {
deferred.reject(error);
}
);
return deferred.promise;
};
this returns a response that looks like this:
Object {current_condition: Array[1], nearest_area: Array[1], request: Array[1], weather: Array[5]}
now inside, lets say, current_condition, it looks like this:
0: Object
FeelsLikeC: "17"
FeelsLikeF: "63"
cloudcover: "0"
humidity: "23"
observation_time: "09:51 AM"
precipMM: "0.0"
pressure: "1028"
temp_C: "17"
temp_F: "63"
visibility: "10"
weatherCode: "113"
weatherDesc: Array[1]
weatherIconUrl: Array[1]
winddir16Point: "WSW"
winddirDegree: "250"
windspeedKmph: "7"
windspeedMiles: "4"
__proto__: Object
length: 1
__proto__: Array[0]
the only problem is when I try access it in my html I get no out put:
{{place.current_condition.FeelsLikeC}}
does not seem to output anything...
Upvotes: 0
Views: 676
Reputation: 540
If places is javascript object, then you can use
places.current_condition[0].FeelsLikeC
If places is array, you can use something like
places[0].current_condition[0].FeelsLikeC
as current_condition is an array.
Upvotes: 3