How do I update the contents of an RSS feed with Ionic refresher? I'm using the Google Feed API (https://developers.google.com/feed/v1/reference). The RSS feed works but the content is not updated and the method doRefresh()
does not work properly:
myApp.controller('rssController', function($ionicPlatform, $http, $scope, $cordovaNetwork, $ionicLoading, $location, $rootScope, $ionicPopup, $timeout, $cordovaToast) {
var options = {
location: 'yes',
clearcache: 'yes',
toolbar: 'yes',
closebuttoncaption: 'DONE?'
};
$ionicLoading.show({
template: 'loading ...'
});
$scope.init = function() {
var handelsBlatt = "http://www.handelsblatt.com/rss/hb.xml";
var schwarzwaelderBote = "http://www.schwarzwaelder-bote.de/moenchweiler.rss.feed";
var suedkurier = "http://feeds.feedburner.com/suedkurier-aktuell";
//Using Google API to fetch all of a Feed's items
//v The version of the API. Currently we are on version 1.0
//q The query to be used in the API. The URL with the RSS feed represents our query
//num The number of entries to return. Default is 4 and maximum is 100
var feed = $http.get("http://ajax.googleapis.com/ajax/services/feed/load", { params: { "v": "1.0", "q": handelsBlatt, "num":20 } })
.success(function(data) {
$ionicLoading.hide();
$scope.rssTitle = data.responseData.feed.title;
$scope.rssUrl = data.responseData.feed.feedUrl;
$scope.rssSiteUrl = data.responseData.feed.link;
$scope.entries = data.responseData.feed.entries;
window.localStorage["entries"] = JSON.stringify(data.responseData.feed.entries);
})
.error(function(data) {
console.log("ERROR: " + data);
$ionicLoading.hide();
var alertPopup = $ionicPopup.alert({
title: 'no connection!',
template: 'Please check your Internet connection!'
});
if(window.localStorage["entries"] !== undefined) {
$scope.entries = JSON.parse(window.localStorage["entries"]);
}
});
}
//open the rss entry in web browser
$scope.browse = function(v) {
window.open(v, "_blank", options);
}
//update the content of RSS-List
$scope.doRefresh = function() {
console.log('Refreshing!');
$http.get("http://ajax.googleapis.com/ajax/services/feed/load", { params: { "v": "1.0", "q": handelsBlatt, "num":20 } })
.success(function(newItems) {
$scope.items = newItems;
})
.finally(function() {
// Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
$cordovaToast.showLongBottom('This could be your text!')
});
}
});
HTML:
<ion-content ng-controller="rssController" ng-init="init()">
<ion-refresher
pulling-text="The content is updated..."
on-refresh="doRefresh()">
</ion-refresher>
<div class="list">
<div ng-repeat="entry in entries" class="item" ng-click="browse(entry.link)">
<b>{{entry.title}}</b><br>
<span>{{entry.publishedDate}}</span><br>
<span ng-bind-html="entry.contentSnippet"></span>
</div>
</div>
</ion-content>