I'm currently learning AngularJS by creating a simple RSS feed. I have successfully made a JSON request and fetched all the data including title, link, description, and images from the RSS feed I parsed. The code snippet for extracting images looks like this:
angular.forEach(feed.entries, function(value){
value.myImage = $(value.content).find('img').eq(0).attr('src');
console.log('image' + value.myImage);
}
However, some feeds have a different structure where images are placed inside
<description> </description>
, such as in this example. I am trying to retrieve images from these feeds using the following method:
angular.forEach(feed.entries, function(value){
value.myImage = $(value.description).find('img').eq(0).attr('src');
console.log('no image' + " " + value.myImage);
});
Unfortunately, I keep getting 'undefined' when trying to display the image from these feeds. I've tried various approaches but seem to be stuck. Any assistance would be greatly appreciated!
Thank you :)
Below is the JSON object I receive:
Object {feedUrl: "https://www.behance.net/rss", title: "Behance Featured Projects", link: "http://www.behance.net", author: "", description: "The latest projects featured on Behance"...}
$$hashKey: "027"
author: ""
description: "The latest projects featured on Behance"
entries: Array[10]
0: Object
$$hashKey: "029"
author: ""
categories: Array[0]
content: "<img src="https://mir-s3-cdn-cf.behance.net/projects/404/2e322a33145177.Y3JvcCw4ODMsNTI5LDAsNzc.jpg" style="float:left;margin-right:15px"><br> Various Illustrations by Patryk Hardziej / 2015"
contentSnippet: "Various Illustrations by Patryk Hardziej / 2015"
link: "https://www.behance.net/gallery/33145177/Various-Illustrations-2015"
publishedDate: "Thu, 28 Jan 2016 08:00:02 -0800"
sImage: undefined
title: "Various Illustrations 2015"