离子弹出警报未正确关闭

时间:2018-03-19 13:43:21

标签: javascript angularjs ionic-framework

第一个警报会验证输入的密码是否与用户密码相对应 如果是,则打开另一个警报,如果用户在两个字段中输入了相同的密码,则用户更改密码 最后,如果第三个警报已成功更改密码,则会打开第三个警报

如果我在第二个警报中单击取消或确认第三个警报后出现问题 之后,在卸载并重新启动相同的应用程序之前,我无法点击应用程序内的任何内容

所以我猜问题出现是因为警报没有正确关闭

这是我的代码:

$scope.changePass = function () {
$scope.newitem = {}

var myPopup = $ionicPopup.alert({
  template: '<input type="password" placeholder="password" ng-model="newitem.password">',
  title: 'Insert your password',
  scope: $scope,
  buttons: [
    { text: 'Cancel' },
    {
      text: '<b>Confirm</b>',
      type: 'button-positive',
      onTap: function(e) {
          if (!$scope.newitem.password) {
            console.log("preventing default");
            e.preventDefault();
          } else {
            if($scope.newitem.password == $scope.user.password) {
              $scope.new = {}
              var newPass = $ionicPopup.alert({
                template: '<input type="password" placeholder="password" ng-model="new.newpass"><br><input type="password" placeholder="Repeat password" ng-model="new.repeatpass">',
                title: 'Insert your new password',
                scope: $scope,
                buttons: [
                  { text: 'Cancel' },
                  {
                    text: '<b>Confirm</b>',
                    type: 'button-positive',
                    onTap: function(e) {
                        if (!$scope.new.newpass) {
                          console.log("preventing default");
                          e.preventDefault();
                        } else {
                          if (!$scope.new.repeatpass) {
                            $scope.new.newpass = "";
                            console.log("preventing default");
                            e.preventDefault();
                          } else {
                            if ($scope.new.newpass == $scope.new.repeatpass) {
                              $scope.user.password = $scope.new.newpass;
                              var uri = "http://someLink" + $window.localStorage.id;
                              $http({
                                  method: 'PUT',
                                  url: uri,
                                  headers: {"Content-Type": "application/json;charset=UTF-8"},
                                  data: $scope.user
                              }).success(function() {
                                var succesResponse = $ionicPopup.alert({
                                  title: 'Ok',
                                  template: "Password has changed"
                                });
                                succesResponse;
                                e.preventDefault();
                              });
                            }
                            else {
                              $scope.new.newpass = "";
                              $scope.new.repeatpass = "";
                              e.preventDefault();
                            }
                          }
                        }
                    }
                  }
                ]
              });
            }
            else {
              $scope.newitem.password = "";
              e.preventDefault();
            }
          }
      }
    }
  ]
});
}

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案

即,解决方案是在打开第二个警报之前关闭第一个警报 但在我打开第二个警报之前,有必要暂停以正确关闭第一个警报

myPopup.close();
$timeout(function() {
    $scope.new = {}
    var newPass = $ionicPopup.alert({...});
}, 500);