以下是重现步骤:
- Create a basic ionic project
ionic start test sidemenu
- Add the android platform
ionic platform add android
In app.js add the code:
$ionicPlatform.registerBackButtonAction(function (event) { alert("back button action handler"); event.preventDefault(); }, 999);
This code can be added in the .run method or in the
$ionicPlatform.ready()
method - same result, not workingionic build android
thenionic upload
-> or manually put the APK on a device
[错误] - 警报未显示,而是执行了历史视图导航。就像我尝试注册的这个操作没有被考虑一样。
我做错了什么?我在控制器中尝试了这段代码,也尝试了 e.stopPropagation()
或 e.stopImmediatePropagation
,但仍然没有成功。
我使用的是最新的Ionic(1.4.5)和Cordova 4.3.0,在一些三星设备上进行了测试。在Ripple中,它可以正常工作。