Get Image Url From RSS MEDIUM FEED

1.2k Views Asked by At

I am trying to display each image from each post from medium's rss feed, without using JQuery, but only javascript or angular, in HTML. Is it possible to get the image from the RSS feed? I am receiving the title, the date it was created at and the link. I am working with Ionic2.

entries: any    = null;
image: any      = null; 

In my constructor:

        Feed.load('https://medium.com/feed/@jaymelone', (err, rss) => {
        if (err) {
            console.log(err);
        }
        else {
            this.entries    = rss.items;
            this.image = this.entries.find('img').eq(0).attr('src');
        }
        console.log("RSS function - entries:", this.entries);
        console.log("RSS function - image: ", this.image);
    });

In my HTML

    <div class="post" *ngFor="let entry of entries">
      <div class="inner">
        <img class="img" [src]="entry.image">
        <p class="title">{{entry.title}}</p>
     </div>
   </div>

But I receive:

<img class="img" src="undefined">

And:

TypeError: Array.prototype.find callback must be a function
2

There are 2 best solutions below

2
On

Assuming that your console.log call is outputting the image name correctly, everything looks in order except you need to use ng-src instead of src, like this:

<img class="img" ng-src="{{entry.image}}">
0
On

Try entry.image.url.

Example:

<img class="img" [src]="entry.image.url">