我的应用程序的后退按钮有问题。
一开始我以为是Cordova的问题,后来发现是Ionic的问题。
我在研究解决方案时发现了这段代码:
// Disable BACK button on home
$ionicPlatform.registerBackButtonAction(function (event) {
if($state.current.name=="app.home"){
navigator.app.exitApp();
}
else {
navigator.app.backHistory();
}
}, 100);
但是,它给出了以下错误:
Uncaught ReferenceError: $ionicPlatform is not defined
我将该代码放在一个名为 functionAngular.js
的新文档中,并将其添加到 body
标记的末尾。因为我必须通知此功能?
我的问题是:
I want my back button to send the user further back in the navigation stack instead of closing the application instantly.
非常感谢您的帮助。
最佳答案
我建议您首先在 Controller 中添加 $ionicPlatform,并在加载的第一个 Controller 中测试后退按钮应具有不同操作的每个状态(见下文)。
$ionicPlatform.registerBackButtonAction(function () {
if ($state.current.name == " login (example) ") {
ionic.Platform.exitApp();
}
if ($state.current.name == " main menu buttons (example) ") {
// Sample message "want to exit the application?" (YES/NO)
if (YES) {
$ionicViewSwitcher.nextDirection('back');
$state.go(' ????');
};
};
if ($state.current.name == " order (example) ") {
// Sample message "want to exit the order?" (YES/NO)
if (YES) {
$ionicViewSwitcher.nextDirection('back');
$state.go(' ????');
};
};
}, 100);
关于javascript - ionic 后退按钮的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34434446/