这是我的控制器:明确的时间间隔不工作
.controller('mainController', function($http, $scope, $timeout, $sce, updateService) {
updateData = function() {
updateService.getDataA($http, $scope);
updateService.getDataB($http, $scope, $sce);
}
var updateIntervalId = setInterval(updateData, 1000);
})
现在,当用户刷新页面个旧请求仍然被提出,我试图把这个间隔号召下将其取消:
window.onbeforeunload = function() {
console.log('interval killed');
clearInterval(updateIntervalId);
}
控制台正在记录'间隔死亡',所以它正在执行,但请求仍在进行,为什么?
使用'var updateIntervalId',您可以将变量'updateIntervalId'绑定到回调函数'function($ http,$ scope,$ timeout,$ sce,updateService){',因此无法从您的'onbeforeunload '回调。 –