1分後に更新されたビューがあり、このビューを終了する前にタイマーを停止しても問題ありません。 現在のビューに戻ると、タイマーは再び再開しません。AngularJs&Ionic:変更するとタイムアウトを再開し、表示に戻る
これは、このビューのコントローラのコードです:あなたが戻って現在のビューに行くとき
.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";
});
それが問題でした。角度サービス[$ interval](https://docs.angularjs.org/api/ng/service/$interval)をいつでも使用できます。 – LeftyX