Hi all, I am writing a simple list to fetch firebase database using ionic 1 and it’s no problem. However, I would like to make the list auto-update whenever there are changes from firebase database. My code is as below and may I know is there any idea how to let the list update in real time syn? Many thanks.
newslist.js
$scope.$on('$ionicView.enter', function() {
$scope.news = [];
firebase.database().ref('news').limitToLast(100).once('value').then(function(news) {
if (news.exists()) {
news.forEach(function(account) {
var getnews = {
brief: account.val().brief,
details: account.val().details,
news_date:account.val().news_date,
thumbnail_url:account.val().thumbnail_url,
id: account.val().news_id
};
$scope.news.push(getnews);
$scope.$apply();
});
}
});
});
}
}
newslist.html
<div class="list card" ng-repeat=“new in news | orderBy:'-'">
<div class="item item-image" >
<img src={{new.thumbnail_url}} >
</a>
</div>
</div>