誰能告訴我,爲什麼我得到以下幾點:
在我的控制,我使用角資源指令做一個正常調用的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