これは私の最初の角度アプリですので、私は間違っているとはっきりしていると確信していますが、私はグーグルで幸運なしにこのサイトを検索しました。返されたオブジェクトにアクセスできません - リソースサービス
天気APIからJSONを取得するためにAJAX呼び出しを行うために$リソースサービスを使用しています。以下の関数はweatherServiceの関数を介してそれを取得し、返されたオブジェクトを画面に正常に記録することができます(console screenshot)。オブジェクトのプロパティ(例:info.cnt)にアクセスしようとすると、ログにはが定義されていません。が返されます。なぜこれが分かりませんか?どんな助けでも大歓迎です。
$scope.submit = function() {
var info = weatherService.getForecast(weatherService.city);
console.log(info);
}
マイカスタム気象サービス:
weather.service('weatherService', function($resource){
this.city = 'Chicago, IL';
this.getForecast = function(location) {
this.weatherAPI = $resource("http://api.openweathermap.org/data/2.5/forecast/daily", { callback: "JSON_CALLBACK" }, { get: { method: "JSONP" }});
this.weatherResult = this.weatherAPI.get({ q: this.city, cnt: 5, appid: 'e92f550a676a12835520519a5a2aef4b' });
return this.weatherResult;
}
});
行い、このください.. 'weatherService.getForecast(weatherService.city).thenを(関数(応答){にconsole.log(response.data.cnt);}、関数(応答){//エラー} ); ' – developer033
これは、TypeErrorを試しました:_angular.min.js:118 TypeError:weatherService.getForecast(...)。次に関数ではありません。 – Tim