1
由於計時器問題,我被卡住了。Ionic&AngularJS,超時未取消
簡而言之,代碼提交表單,並且在iFrame中打開對帖子的回答。 表單上的EventListener允許我檢測「提交」並應用計時器來檢測iFrame加載是否過長。 但是,即使加載了iFrame(=取消定時器),定時器的功能也會被調用。 下面是代碼:
[...]
var el = document.getElementById("myForm");
if(el){
el.addEventListener("submit", function(event){
$scope.popupOpened=false;
var iframeWindow = window.parent.document.getElementById('myIframe');
var iframeDoc = iframeWindow.contentWindow.document;
//7 seconds before the popup is shown up
$rootScope.myTimer = $timeout(function(){
window.frames[0].stop();
if(!$scope.popupOpened){
errorConnexion2();//popup opening
}
}, 7000);
iframeWindow.onload=function(){
console.log("iframe loaded");
//cancel the timer
$timeout.cancel($rootScope.myTimer);
}
});
}
[...]
我也試圖與setTimeout和clearTimeout並通過清除所有的人都這樣:Is there a way to clear all time outs?
我缺少什麼? 提前謝謝!