Dies ist das erste Mal, dass ich Angularjs $ resource nutze und versuche, meine Anwendung zu testen. Ich versuche, auf eine der Eigenschaften zuzugreifen, anstatt das gesamte Objekt anzuzeigen. Wie kann ich auf data.image oder data.url zugreifen?
json Daten von Weather Underground
{
"response": {
"version":"0.1",
"termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
"features": {
"conditions": 1
}
}
, "current_observation": {
"image": {
"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
"title":"Weather Underground",
"link":"http://www.wunderground.com"
},
"display_location": {
"full":"San Francisco, CA"
}
Wetter Fabrik
app.factory('weatherService',['$resource', function($resource){
var factory={};
factory.getWeather = function(){
return $resource("http://api.wunderground.com/api/9eb7777065b59c55/conditions/q/CA/San_Francisco.json").get();
}
return factory;
}]);
Wetter Controller
app.controller('weather', ['$scope', '$http','weatherService', function($scope, $http, weatherService){
$scope.weather = weatherService.getWeather().get();
}]);
Warum machst du '.get()' zweimal? Einmal in der Fabrik und einmal im Controller? –