"node" : {
"title": "Event hold tomorow",
"field_mobile_image" : " {'src' : 'http://www.example.com/sites/default/files/image_default_banner.jpg','alt' : ''}"
}
}, "node" : {
"title": "Event hold tomorow",
"field_mobile_image" : " {'src' : 'http://www.example.com/sites/default/files/image_default_banner.jpg','alt' : ''}"
}
}
I have some JSON data that looks like the above from an API I am trying to display this result in a loop with angujarjs i can't figure out how to read the value of 'src' i keep getting an undefined
my template looks like this
<a class="list card" ng-repeat="newsitem in news" style="display:block;text-decoration:none;" ui-sref="menu.newsDetail()" id="news-card22">
<img ng-src="{{newsitem.node.field_mobile_image.src}}">
<i class="icon ion-android-calendar"></i>{{newsitem.node.title}}</ion-item>
the controller looks like this
function($scope, $stateParams, getPageInfo) {
getPageInfo.news().then(function(res) {
$scope.news = res;
});
The service looks like
.service('getPageInfo', ['$http', function($http) {
news: function() {
let api_url = "http://example.com/";
endpoint = "api/news";
return $http.get(api_url + endpoint).then(function(resp) {
console.log(resp.data.data[0].node.field_mobile_image.src); //undefined
return resp.data.data
});
}
return ret;
}]);
newsarrayng-srcinstead ofsrcmore details is here w3schools.com/angular/ng_ng-src.asp