此代码在退出页面时触发两次promptForUnSavedChanges函数。如何使提示只显示一次?
cleanupTransitionHook = $transitions.onExit({},
promptForUnsavedChanges);
function promptForUnsavedChanges() {
if (ctrl.forms.updateRecipe.$dirty || ctrl.changedPortionCount) {
if ($window.confirm('You will lose unsaved changes if you leave this page')) {
if (ctrl.changedPortionCount) {
ctrl.recipeModel.updateCurrentUserMetaPortionSizeRatio(ctrl.originalScaleFactor, ctrl.userRanges);
}
return true;
}
return false;
}
return true;
}
答案 0 :(得分:0)
$ transitions.onExit函数返回是删除器函数。
因此您在返回true之前先调用该函数
ex)cleanupTransitionHook();