谁能告诉我,为什么我得到以下几点:
在我的控制,我使用角资源指令做一个正常调用的API。
$scope.weatherAPI = $resource('http://api.openweathermap.org/data/2.5/forecast/daily', {callback: 'JSON_CALLBACK'}, {get: {method: 'JSONP'}});
$scope.weatherResult = $scope.weatherAPI.get({ q: $scope.city, cnt: 4, APPID: 'xxxxxx' });
并将结果打印到控制台。
console.log($scope.weatherResult);
console.log($scope.weatherResult.city)
console.log("scope weatherResult " + $scope.weatherResult);
console.log("scope weatherResult.list: " + $scope.weatherResult.list);
console.log("scope weatherResult.city: " + $scope.weatherResult.city);
但是,这是结果。正如你所看到的那样,即使对象是通过$scope.weatherResult
进入,当我尝试并定位其中一个属性时,我得到undefined
,因此我无法使用该数据。
返回结果是承诺对象,您不应该尝试从属性中检索数据。只需检查文档中的示例https://docs.angularjs.org/api/ngResource/service/$resource – sdfacre