我使用以下代码来使用 $ionicPopup 和 Firebase 进行一些验证:
onTap: function(e) {
firebase.auth().applyActionCode($scope.data.emailcnfrm)
.then(function() {
return $scope.data.emailcnfrm;
},
function(error) {
alert("wrong code");
e.preventDefault();
});
}
但是如果出现错误,并且在收到“错误代码”警报后,弹出窗口将关闭,因为 e.preventDefault();
已被忽略。
那么我的代码到底有什么问题呢?我该如何解决这个问题?
最佳答案
对 firebase.auth().applyActionCode
的调用是异步的,e.preventDefault
将在错误回调中异步调用。这种情况发生在用户已经调用 onTap
之后,因此 e.preventDefault
不会产生任何效果。
编辑(建议的修复)
要修复此问题,您可以将异步逻辑与 onTap
方法分开:
var myPopup = $ionicPopup.show({
onTap: function(e) {
// always keep the popup open, because we'll decide when to close it later
e.preventDefault();
}
});
myPopup.then(function(res) {
firebase.auth().applyActionCode($scope.data.emailcnfrm)
.then(function() {
// if successful, imperatively close the popup
myPopup.close();
}, function(err) {
// log the error, or something
});
});
关于javascript - $ionicPopup : e. PreventDefault() 被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37505089/