I am dealing with a JSON file that contains 2 arrays holding some data which I need to retrieve for my AngularJS website. My aim is to extract a single object from these 2 arrays.
JSON data
[
{
"DailyForecasts": [
{
"key": "32.48,44.46",
"class": "forecast",
"validDate": 1484236800,
"maxTemp": 17,
"minTemp": 3,
"precip_type": "rain",
"day": {
"humid": 34,
"wSpeed": 20,
"wDir": 297,
"pop": 0,
"uv": 2,
"icon": 34,
"wDirText": "غرب-شمال غ",
"phrase": "مشمس بصورة كلية",
"bluntPhrase": "",
"precip_type": "rain",
"snwAccumPhrase": "",
"snwAccumPhraseTerse": "",
"extQual": "",
"weatherCode": "3400"
},
"night": {
"humid": 64,
"wSpeed": 20,
"wDir": 297,
"pop": 0,
"uv": 0,
"icon": 33,
"wDirText": "غرب-شمال غ",
"phrase": "صافي بصورة كلية",
"bluntPhrase": "",
"precip_type": "precip",
"snwAccumPhrase": "",
"snwAccumPhraseTerse": "",
"extQual": "",
"weatherCode": "3300"
}
},
{
"key": "32.48,44.46",
"class": "forecast",
"validDate": 1484323200,
"maxTemp": 17,
"minTemp": 5,
"precip_type": "rain",
"day": {
"humid": 48,
"wSpeed": 14,
"wDir": 287,
"pop": 0,
"uv": 3,
"icon": 32,
"wDirText": "غرب-شمال غ",
"phrase": "مشمس",
"bluntPhrase": "",
"precip_type": "rain",
"snwAccumPhrase": "",
"snwAccumPhraseTerse": "",
"extQual": "",
"weatherCode": "3200"
},
"night": {
"humid": 67,
"wSpeed": 14,
"wDir": 287,
"pop": 10,
"uv": 0,
"icon": 31,
"wDirText": "غرب-شمال غ",
"phrase": "صافي",
"bluntPhrase": "",
"precip_type": "rain",
"snwAccumPhrase": "",
"snwAccumPhraseTerse": "",
"extQual": "",
"weatherCode": "3100"
}
}
]
}
]
Controller Code
app.controller('Hillahctlr', function($scope, $http, wind, arrivecss, windname, icons) {
$scope.wind_dir = wind;
$scope.icons = icons;
$scope.arrivecss = arrivecss;
$scope.windname = windname;
var service_url = "/key=e88d1560-a740-102c-bafd-001321203584&units=m&locale=ar&cb=JSON_CALLBACK";
$http.jsonp(service_url)
.success(
function(data) {
console.log(data);
yData = data.HourlyForecasts;
$scope.ali = [];
for (var i = 0; i < 9; i++)
{
$scope.ali[i] = {
dayes: yData[i].temp,
};
}
})
})
}
I tried looping inside this array using ng-repeat, but unfortunately it's not working as expected. Here is the code:
HTML
<div class="ForecastArea-Day Last weatherteble" ng-repeat="alis in dayes">
{{alis.dayes}}
</div>
An error message stating Error: yData is not defined
keeps popping up. Any assistance would be greatly appreciated.