How to get PublishingImage field of a list using angular JS?
1 Answer
I don't think you can get it directly, but you can get it through FieldValuesAsHtml
, but only if you query one and one item.
Something like this:
$http.get("/_api/Lists/GetByTitle('Articles')/Items").then(function (res) {
angular.forEach(res.data.d.results, function (article) {
$http({
url: article.FieldValuesAsHtml.__deferred.uri,
params: {
$select: "PublishingImage"
}
}).then(function (res) {
article.PublishingImage = res.d.PublishingImage;
});
});
});
You could also use $q.all
to wait for the image urls to load, although there is no need, you can use {{article.PublishingImage}}
in your template directly.
Note that the field will be encoded, so you'll need to either decode it or extract the url.