I am refreshing message list with Ionic Framework Ion Refresher.
Although JSON is returned in good response , ionRefresh is not updating list on pull to refresh.
Why is it not showing the updated scope? can anybody help me?
angular.module('starter.controllers', [])
.factory("Messages", function () {
var Messages = {};
return{
getData: function($http) {
return $http.get("http://website.com/index.php/id/user/get_message/i").
success(function(response) {
/// console.log(JSON.stringify(response));
Messages.data=response.data;
return Messages;
}).error(function(data, status, headers, config) {
// log error
});
}
}
.controller('MessagesCtrl',function ($scope, Messages,$http,$ionicPopup,$timeout,$window) {
$scope.messages =[];
$scope.doRefresh = function() {
// $window.location.href = "http://website.com/index.php/id/user#/app/message";
$scope.messages =[];
$http.get("http://m.sepakbola.cc/index.php/id/user/get_message/i").then(function(msg){
console.log($scope.messages); //empty
$scope.messages=msg;
console.log($scope.messages); // filled with updated list
})
.finally(function() {
// Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
});
};
Messages.getData($http).then(function(data,$rootScope) {
$scope.messages = data;
});
Template
<ion-refresher
pulling-text="Pull to refresh..."
on-refresh="doRefresh()" ng-controller="MessagesCtrl">
</ion-refresher>
<ion-list ng-controller="MessagesCtrl">
<ion-item ng-show="messages.data.length" ng-repeat="message in messages.data"
id="message{{message.id}}" class="item">
<a class="messageIcon">{{message.admin}}</a>
<p>{{message.title}}</p><a ng-click="deleteItem($index)">
<img src="/_aps4497/assets/16/trash-icon.png"/></a>
<button class="button button-stable" ng-click="showAlert($index)">Open</button>
</ion-item>
<ion-item ng-show="!messages.data.length" class="item">
No Messages
</ion-item>
</ion-list>
JSON:
{"id":"9001301","admin":"xxx","title":"**xxx**",
"date":"19\/01\/2015 21:33:31","descr":"xxx"},
{"id":"9001300","admin":"xx","title":"xx","date":"19\/01\/2015 21:28:11","descr":"xx"}]