I’m trying to reload the newsfeed everytime it enters the screen. It works when it is first loaded and using $state.go (e.g. after posting a picture it reloads with the picture). Although, if I go to a different tab and come back, the screen is blank (until i refresh or click the tab once again). Ive tried adding ui-sref-opts="{reload:true}" to the tabs.html but no help.
Controller:
var self = this;
this.images =[];
var user = Parse.User.current();
var i =0;
this.loadImages = function(){
var imageGallery = Parse.Object.extend("Gallery");
var query = new Parse.Query(imageGallery);
query.include("user");
query.near("location", $rootScope.currentLocation);
query.find({
success: function(results) {
for (i;i<results.length;i++) {
var object = results[i];
self.images.push({
locationName: object.get('locationName'),
caption: object.get('caption'),
img: object.get('img').url(),
username: object.get('user').get('username'),
userprofpic: object.get('user').get('profpic').url()
});
}
},
error: function(error) {
}
});
};
$scope.$on('$ionicView.loaded', function(){
self.loadImages();
});
$scope.$on('$ionicView.enter', function(){
self.loadImages();
});
this.doRefresh = function(){
$state.reload();
$scope.$broadcast('scroll.refreshComplete');
};
HTML:
<ion-view title="Nearby" hide-back-button="true" cache-view="false"> <ion-content class="has-header" overflow-scroll="false"> <ion-refresher pulling-text="Pull to refresh..." on-refresh="home.doRefresh()"></ion-refresher> <newsfeed-item ng-repeat="image in home.images"></newsfeed-item> </ion-content> </ion-view>
Custom Directive:
return{ restrict: 'E', templateUrl: 'templates/newsfeed-item.html', replace: true };