天天看點

ionic開發——Android 傳回鍵

傳回鍵處理,隻需要在run方法裡添加如下代碼:

$ionicPlatform.registerBackButtonAction(function (e) {
    e.preventDefault();
    function showConfirm() {
        var confirmPopup = $ionicPopup.confirm({
            title: '<strong>退出應用?</strong>',
            template: '你确定要退出應用嗎?',
            okText: '退出',
            cancelText: '取消'
        });
        confirmPopup.then(function (res) {
            if (res) {
                ionic.Platform.exitApp(); //退出
            } else {

            }
        });
    }

    if ($location.path() == '/home/homeInfo') {
        showConfirm();
    } else if ($ionicHistory.backView()) {
        $ionicHistory.goBack(); //傳回
    } else {
        showConfirm();
    }
    return false;
}, 101);
           

繼續閱讀