Javascript $ionicPopup:e.preventDefault()被忽略

Javascript $ionicPopup:e.preventDefault()被忽略,javascript,angularjs,ionic-framework,firebase,ionic-popup,Javascript,Angularjs,Ionic Framework,Firebase,Ionic Popup,我使用$ionicPopup和Firebase使用以下代码进行一些验证: onTap: function(e) { firebase.auth().applyActionCode($scope.data.emailcnfrm) .then(function() { return $scope.data.emailcnfrm; }, function(error) { alert("wro

我使用$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方法分离:


最后,我用自己的技巧解决了这个问题:

-外部异步:

         $scope.myPopup = $ionicPopup.show({

             scope: $scope, buttons: [

             { text: 'Cancel' },

             {                  
                 text: '<b>Done</b>',

                 type: 'button-positive',

                 onTap: function(e)
                 {

                 // always keep the popup open, because we'll decide when to close it later
                 e.preventDefault();

                 $AsyncCallback();
                 }
             }
             ]
         });

$scope.myPopup.then(function(){},
                             function(error)
                             {
                                 $ionicPopup.alert({

                                 title: 'Internal error!',

                                 template: error
                                 });
                             });

我尝试了您推荐的方法,但没有按预期工作:myPopup.then在myPopup关闭后执行。
         $scope.myPopup = $ionicPopup.show({

             scope: $scope, buttons: [

             { text: 'Cancel' },

             {                  
                 text: '<b>Done</b>',

                 type: 'button-positive',

                 onTap: function(e)
                 {

                 // always keep the popup open, because we'll decide when to close it later
                 e.preventDefault();

                 $AsyncCallback();
                 }
             }
             ]
         });

$scope.myPopup.then(function(){},
                             function(error)
                             {
                                 $ionicPopup.alert({

                                 title: 'Internal error!',

                                 template: error
                                 });
                             });
$scope.myPopup.close();