I have a simple service that gets some openWeather JSON. The service is then injected into the controller. In the controller, I cannot access the objects withing the JSON, however, when binding to the, I can access the object data without problem. I'm new to JS and Angular, what am I doing wrong?
Service
mcmdApp.service('areaWeatherService', ['$resource', function($resource){
this.weatherAPI = $resource("http://api.openweathermap.org/data/2.5/weather", {get: {method: "JSON"}});
this.weatherResult = this.weatherAPI.get({q: "London,uk"});
}]);
Controller
mcmdApp.controller('SingleElementController',['$scope', 'areaWeatherService',function($scope, areaWeatherService){
$scope.weatherResult = areaWeatherService.weatherResult;
console.log($scope.weatherResult); //<-- Shows Object in Console
console.log($scope.weatherResult.wind); //<-- PROBLEM: Shows Undefined
console.log($scope.weatherResult.wind.speed); //<-- PROBLEM: Shows cannot read property 'speed' of Undefined
}]);
View
<div class="single-element-widget text-center">
<h2>{{weatherResult.wind.speed}} mph</h2><!-- NO PROBLEM, displays correctly -->
<small>{{weatherResult.wind.deg}} degrees</small><!-- NO PROBLEM, displays correctly -->
</div>
I'm attempting to access the objects and properties from either the Controller or Service.
Results of console.log($scope.weatherResult);
e {$promise: d, $resolved: false}$promise: d$resolved: truebase: "cmc stations"clouds: Objectcod: 200coord: Objectdt: 1441164423id: 2643743main: Objectname: "London"sys: Objectweather: Array[1]wind: Object__proto__: e
console.log($scope.weatherResult);