【发布时间】:2016-06-23 10:32:14
【问题描述】:
我使用 angular $time out 从 api 重新加载数据并在 dom 中显示实时统计数据。重新加载效果很好,5秒后重新加载。但问题是,在我点击另一个选项卡后,我不需要 $timeout 并重新加载数据,仍然像之前的页面一样重新加载数据。该数据不在 DOM 中,但在网络控制台中仍从以下代码重新加载数据,并使用该数据调用 http get url。
$scope.reload = function () {
$http.get(serviceBase + 'live-stats').
success(function (res) {
$scope.proizvedeno = res;
console.log(res);
});
$timeout(function(){
$scope.reload();
}, 5000);
};
$scope.reload();
附:我使用 angular-loading-bar,有没有办法让这个栏在重新加载页面的某个部分时不旋转,在这种情况下,从“超时”中检索数据以显示统计信息
编辑: 我将此添加到此 ctrl
$scope.reload = function () {
$http.get(serviceBase + 'live-stats').
success(function (res) {
$scope.proizvedeno = res;
console.log(res);
});
$timeout(function(){
$scope.reload();
}, 5000);
$scope.$on('$destroy', function(){ //this is what i add
$timeout.cancel(reload); //this is what i add
};
$scope.reload();
但超时仍未取消
【问题讨论】: