NPM RSS2JSON
npm install rss-to-json --save
npm install @types/node --save-dev
(Provider)
getJsonFromRSS(): Promise<any> {
return new Promise(resolve => {
var Feed = require('rss-to-json');
let _URL = "http://rssurl.com/";
let listRSS: any[] = [];
Feed.load(_URL, function (err, result) {
for (let i = 0; i < result.items.length; i++) {
listRSS.push(JSON.parse(JSON.stringify(result.items[i])));
}
resolve(listRSS);
});
});
}
}
----------------------------------
(Client)
rssList: {
title: string;
link: string;
description: string;
pubDate: Date;
}[] = [];
loadRssData() {
getJsonFromRSS().then(dataList => {
let data = JSON.parse(JSON.stringify(dataList));
for (var i = 0; i < data.length; i++) {
let itemRSS: {
title: string;
link: string;
description: string;
pubDate: Date;
} = { title: data[i].title, link: data[i].link, description: data[i].description, pubDate: new Date(data[i].created) };
this.rssList.push(itemRSS);
}
this.rssList.sort((a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime());
});
}