我有一个离子应用程序,用户点击一个按钮,然后弹出一个弹出窗口,然后用户点击弹出窗口中的一个按钮,另一个显示。 这在浏览器中工作正常,但是当我将其部署到Android设备时,在第二次弹出窗口关闭页面冻结后,我再也无法点击页面上的主按钮。
这是一个简短但完整的应用程序,用于演示我的问题。
<!DOCTYPE html>
<html>
<head>
<title>App</title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<!-- version 1.0.0-beta.9 -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script>
angular.module("app", ["ionic"])
.controller("controller", function ($scope, $ionicPopup, $timeout) {
var popup1;
$scope.popup1 = function () {
popup1 = $ionicPopup.show({
template: '<button ng-click="popup2()">popup2</button>',
title: 'popup1',
scope: $scope
});
}
$scope.popup2 = function () {
$ionicPopup.alert({
title: "Popup 2"
}).then(function () {
/*
$timeout(function () {
popup1.close();
});
*/
popup1.close();
});
}
});
</script>
</head>
<body ng-app="app" ng-controller="controller">
<button ng-click="popup1()">popup1</button>
</body>
</html>
答案 0 :(得分:6)
这不起作用的原因可能是第二个弹出窗口在第一个弹出窗口关闭之前打开,这可能会杀死Ionic知道第一个弹出窗口存在。如果你在打开第二个弹出窗口之前杀掉第一个弹出窗口,那应该可以解决问题。
我看到了几个选项:
<强> 1。以离子方式创建按钮并使用onTap
方法
$scope.popup1 = $ionicPopup.show({
template: 'Your template here',
title: 'popup1',
scope: $scope,
buttons: [
{
text: 'Popup2',
onTap: function (e) {
$scope.popup1.close();
return $scope.popup2();
}
}
]
});
<强> 2。在popup1
popup2()
$scope.popup2 = function () {
$scope.popup1.close();
// Open popup 2
}
第3。暂停时打开popup2
如果以上操作不起作用,请在popup2
的代码周围设置超时,以便让Ionic有时间关闭第一个弹出窗口。
$scope.popup2 = function () {
// Move to the bottom of the queue to let Ionic close the first popup
$timeout( function () {
// Load popup2
});
};
答案 1 :(得分:0)
我的解决方案:
$rootScope.solidAlertPromise = $q.resolve(); // make the very first alert happen immediately
//lets create a reusable function to get rid of static and local problems
window.alert = function(message) {
//chaining does the trick
$rootScope.solidAlertPromise = $rootScope.solidAlertPromise.then(
function() {
//New Popup will rise as soon as the last Popup was closed (resolved).
//but it will rise immediately after closing the last Popup - definitely!
return $ionicPopup.alert({title: 'solidAlert', content: message});
}
);
};
//Now we can call our function sequentially
alert('After max has closed this alert-popup, the next one will rise immediately!');
alert('Next one -press OK to get the nex one-');
alert('and so on');
这只是为了解释eplanation目的:我们应该看看拒绝案件等等!
$ ionicPopup.alert
可以替换为
$ ionicPopup.show
我想。