javascript - ionic 后退按钮的问题

标签 javascript android cordova ionic-framework

我的应用程序的后退按钮有问题。

一开始我以为是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/

相关文章:

JavaScript: "Syntax error missing } after function body"

javascript - 这个高斯模糊 javascript 算法怎么可能工作?

java - 为什么setProgressBackgroundColor无法解决错误?

java - 如何在android中从用户那里获取整数,操作并放置在另一个文本框中

android - ionic 框架移动应用程序大小问题

javascript - 现在有哪些浏览器支持 window.postMessage 调用?

javascript - 使用过滤器返回对象中的属性值

android - Phonegap:如果第一次被拒绝,请再次请求许可

android - 手机间隙 : How to detect android application is running in development mode

javascript - android 上phonegap 项目中的Ajax 请求