PhoneGap的Andr​​oid的后退按钮W /离子和角 [英] Phonegap Android Back Button w/ Ionic and Angular

查看:175
本文介绍了PhoneGap的Andr​​oid的后退按钮W /离子和角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用离子框架/角JS禁用为Android后退按钮在的PhoneGap项目的问题。我曾尝试过许多建议解决方案无济于事。问题是我有一个'登录'屏幕,这是一个模式(ionicModal),但Android用户能够使用返回按钮即可离开,不管他们是在登录与否。

I'm having issues disabling the back button for Android in a Phonegap project using Ionic Framework / Angular JS. I have tried many other proposed solutions to no avail. The problem is I have a 'Login' screen which is a modal (ionicModal), but Android users are able to use the back button to navigate away regardless of if they are logged in or not.

我尝试禁用Android的后退按钮都在一起。该事件触发,但页面导航仍然发生。我觉得,如果这个工作,这将是理想的,最直接的解决方案。这里虽然,preventDefault()和stopPropagation()似乎没有任何效果。

I tried disabling the Android Back button all together. The event fires, but the page navigation still happens. I feel like if this worked, this would be the ideal and most straight forward solution. Here though, preventDefault() and stopPropagation() seem to have no effect.

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    document.addEventListener("backbutton", onBackKeyDown, false);
}

function onBackKeyDown(e) {
    alert('back button triggered');
    e.preventDefault();
    e.stopPropagation();
}

我也试图通过听$ locationChangeStart和preventing,禁用从内部角度导航:

I also tried disabling the navigation from within Angular by listening to $locationChangeStart and preventing that:

// Disable "Back" button on androids if user is on login screen
$rootScope.$on('$locationChangeStart', function(e) {
    if( true ) {
        e.preventDefault();
        e.stopPropagation();
    }
});

这也似乎工作,但但不知何故仍然隐藏模式和去previous屏不prevent Android系统。

This also seems to work, but yet somehow still does not prevent Android from hiding the modal and going to the previous screen.

有没有使用的PhoneGap /离子/角时禁用Android的后退按钮有道?它采用了折角UI路由器,并且该模式不是一个路线,而是一个ionicModal。

Is there a proper way to disable the Android Back button when using Phonegap/Ionic/Angular? It uses the Angular UI router, and the modal is not a route but rather an ionicModal.

推荐答案

似乎有一个名为的hardwareBackButtonClose,你可以在设置模式,以确定是否可以模式使用硬件后退按钮在Android和类似设备被关闭。默认为:真实,所以尽量设置为false

seems that there is a boolean property named "hardwareBackButtonClose" that you can set on the modal to determine whether the modal can be closed using the hardware back button on Android and similar devices. Defaults to: true, so try setting it to false.

这篇关于PhoneGap的Andr​​oid的后退按钮W /离子和角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆