Hi All,
I’m trying to use an $interval to call the server and then update a list.
Seems to work all well (in the log I see the updated array) but the list doesn’t update.
$scope.refreshBatch = function() {
console.log('5s timer');
$http.get('./batch.json', { timeout: 3000 }).then(
function(result) {
$rootScope.batch = result.data;
$scope.hideLoadingPopup();
console.log($rootScope.batch);
},
function(rejected) {
$scope.hideLoadingPopup();
$scope.showErrorPopup('timeout caricamento json', 'Controlla la rete...', true);
}
);
}
$interval(function() { $scope.refreshBatch(); }, 5000);
and there the html pieces:
<ion-content scroll="true" has-bouncing="false" class="main-content">
<div class="row padding-0">
<div class="home-col-spacer"></div>
</div>
<div class="row no-row-effect home-row" ng-repeat="workstation in workstations">
<div class="col home-first-col text-center">
<span class="">{{workstation.id}}</span>
</div>
<div class="col">
<div class="button div-staff" ng-show="workstation.active" ng-class="{0:'ws-red', 1:'ws-green'}[workstation.status]" ng-class-odd="{1:'ws-green-odd'}[workstation.status]">
{{workstation.staffName}}
</div>
</div>
</div>
</ion-content>
SOLVED
I wasn’t updating $rootScope.workstations, so the ng-repeat didn’t update their values.
there the working code:
$scope.refreshBatch = function() {
console.log('5s timer');
$http.get('./batch.json', { timeout: 3000 }).then(
function(result) {
$rootScope.batch = result.data;
$rootScope.workstations = $rootScope.batch[0].workstation;
$scope.hideLoadingPopup();
console.log($rootScope.batch);
},
function(rejected) {
$scope.hideLoadingPopup();
$scope.showErrorPopup('timeout caricamento json', 'Controlla la rete...', true);
}
);
}