0

我编写了一个函数来在单击设备返回时打开离子弹出窗口,问题是只要我多次单击设备返回,弹出窗口就会被创建多次并保留在 DOM 中。如何关闭以前的弹出窗口并再次创建一个新窗口?

应用退出弹出窗口:

 $rootScope.exitApp = function () {


                exitpopup = $ionicPopup.show({
                    templateUrl: 'templates/exitApp1.html'

                });

                exitpopup.then(function (res) {
                    console.log(res);

                });
                return false;
            };

注册返回功能:

 $ionicPlatform.registerBackButtonAction(function (e) {
  // lots of  code 
 if ($ionicHistory.backView())
 $rootScope.exitApp ();
});

我错过了什么吗?

4

1 回答 1

0

希望以下功能对您有所帮助。按下后退按钮时设置标志,如果标志为假,则检查标志,无需再次显示对话框。如果用户按下取消再次更改标志值。

app.run(function($ionicPlatform,$rootScope,$ionicPopup) 
{
    $rootScope.is_dialog_in_screen = false;
    $ionicPlatform.ready(function() 
    {
        if(window.cordova && window.cordova.plugins.Keyboard) 
        {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            cordova.plugins.Keyboard.disableScroll(true);
        }
        if(window.StatusBar) 
        {
            StatusBar.styleDefault();
        }
    });

    $ionicPlatform.registerBackButtonAction(function (event) 
    { 
        event.preventDefault();

        if($rootScope.is_dialog_in_screen==false)
        {
            var confirmPopup = $ionicPopup.confirm({
                title: 'Quit.?',
                template: 'Really want to exit?',
                cancelText: 'cancel',
                okText: 'ok'
            })
            .then(function(res) 
            {
                if (res) 
                {
                    alert("Exit app logic goes here");
                }
                else
                {
                    $rootScope.is_dialog_in_screen = false;
                }
            });

            $rootScope.is_dialog_in_screen = true;
        }
    }, 999);
})
于 2017-09-28T11:00:22.063 回答