Ho una vista che viene aggiornata dopo 1 minuto, interrompo il timer dopo aver lasciato questa visualizzazione e tutto è OK. Dopo il ritorno alla visualizzazione corrente, il timer non si riavvia nuovamente.
Questo è il codice del controllore di questa visione:
.controller('IndexCtrl', function($scope, $timeout, RestService) {
var updateN = 60*1000;
$scope.test = "View 1 - Update";
var update = function update() {
timer = $timeout(update, updateN);
/** make a http call to Rest API service and get data **/
RestService.getdata(function(data) {;
$scope.items = data.slice(0,2);
});
}();
/** Stop the timer before leave the view**/
$scope.$on('$ionicView.beforeLeave', function(){
$timeout.cancel(timer);
//alert("Before Leave");
});
/** Restart timer **/
$scope.$on('$ionicView.enter', function(){
$timeout(update, updateN);
//alert("Enter");
});
})
.controller('ViewCtrl2', function($scope) {
$scope.test = "View 2";
});
Questo era il problema. È sempre possibile utilizzare il servizio angolare [$ interval] (https://docs.angularjs.org/api/ng/service/$interval). – LeftyX