【问题标题】:AngualrJS - Ionic - How to start an async process after the popup closes?AngularJS - Ionic - 弹出窗口关闭后如何启动异步进程?
【发布时间】:2017-10-18 12:48:01
【问题描述】:

我正在使用 Ionic 1.3 和 Angular 1.5 编写应用程序。

我在我的应用中使用 $ionicPopup 服务。

        $ionicPopup.confirm({
            title: getShowPopupTitle(),
            buttons: [{
                text: 'OK',
                type: 'button-positive',
                onTap: function () {
                    processData();
                }
            }, {
                text: 'CANCEL',
                type: 'button-default',
                onTap: function () {
                }
            }]
        });

我的应用有摘要循环和视图更新问题,所以这是我想尝试的:

在用户单击“确定”并且弹出窗口从视图和范围中消失后,我想调用剩余的异步进程。

我怎样才能做到这一点?

【问题讨论】:

  • IMO 你应该修复摘要循环问题而不是绕过它。你能分享导致循环的代码sn-p吗?

标签: angularjs ionic-framework popup angular-promise


【解决方案1】:

您是否尝试过使用.then 回调?

    var popup = $ionicPopup.confirm({
        title: getShowPopupTitle(),
        buttons: [{
            text: 'OK',
            type: 'button-positive',
            onTap: function () {
                processData();
            }
        }, {
            text: 'CANCEL',
            type: 'button-default',
            onTap: function () {
            }
        }]
    });
    popup.then(function(data){
        console.log(data);
    })

如果您在弹出窗口关闭后需要更多时间,那么您可以使用 $timeout 服务。

popup.then(function(data){
    popup.close();
    $timeout(function(){
        // do your thing here...
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多