weatherApp.controller('forecastController', ['$scope','weatherService','$resource','$log', function($scope,weatherService,$resource,$log){
var cnto =3;
$scope.forecastholder = weatherService.holder;
$scope.weatherAPI = $resource("http://api.openweathermap.org/data/2.5/forecast",
{callback: "JSON_CALLBACK"}, {get:{method:'JSONP'}});
$scope.weatherResult = $scope.weatherAPI
.get({
q: $scope.forecastholder, cnt: cnto, appid: "7acd7f3379f4ecc2cd8b5068f06e9ff1"});
});
$ scope.weatherResult.list在控制台中给我未定义。
在html中: {{weatherResult.list}} 它给出了正确的结果。 如何解决这个问题?
答案 0 :(得分:0)
我认为您需要添加then()
才能返回数据。
$scope.weatherResult = $scope.weatherAPI
.get({
q: $scope.forecastholder,
cnt: cnto,
appid: "7acd7f3379f4ecc2cd8b5068f06e9ff1"
}).then(function(response) {
$scope.weatherResult = response;
console.log($scope.weatherResult);
});
答案 1 :(得分:0)
解决方案:
使用$ promise.then(回调)
$scope.weatherResult = $scope.weatherAPI.get({ q: $scope.forecastholder,
cnt: cnto, appid: "7acd7f3379f4ecc2cd8b5068f06e9ff1"}).$promise.then(function(response) {
$scope.weatherResult = response;
console.log($scope.weatherResult.list[0].dt);
});