Phonegap / Angular - angular.element()。scope()不起作用

时间:2014-07-22 21:36:03

标签: javascript android angularjs cordova windows-phone-8

我为我的Phonegap / Angular应用程序覆盖Android / WP8的后退按钮行为。几个星期前我已经实现了它,它的工作就像一个魅力。但是,由于我制作的存储库错误,代码的一部分丢失了。所以今天我一直在重新创建它,但不管我做什么,我都无法在我的MainController中找到我的handleBack()函数。

在我的index.html中,我在标题中包含了我所有的各种.js文件,这是我的身体:

<body ng-view ng-class="slide" ng-controller="MainController" >
    <script type="text/javascript">
        document.addEventListener("deviceready", onDeviceReady, false);

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

        function handleBackButton(event){
            alert("entered handleBackButton");
            angular.element('[ng-controller=MainController]').scope().handleBack(event);
        }
    </script>
</body>

这是我的MainController:

.controller('MainController', ['$scope', '$rootScope', '$window', '$location', 'currentLocale', 'Auth',  
function ($scope, $rootScope, $window, $location, currentLocale, Auth) {
$scope.slide = '';
$rootScope.back = function() {
  $(window).blur();
  $scope.slide = 'slide-right';
  if (typeof (navigator.app) !== "undefined") {
    navigator.app.backHistory();
  } else {
    $window.history.back();
  }
}

$rootScope.go = function(path, direction) {
  $(window).blur();
  $scope.slide = typeof direction !== 'undefined' ? direction : 'slide-left';
  $location.url(path);
}

$rootScope.login = function() {
  $scope.slide = 'slide-right';
  $location.path('/');
  $window.localStorage.clear();
}

$rootScope.logout = function() {
  if(navigator.notification.confirm("Are you sure you want to logout?", 
                                    function(index){
                                      if(index == 1){
                                        Auth.logout(function(data) {
                                            $rootScope.login();
                                        });
                                      }
                                    }, 
                                    "Confirm")) {
    Auth.logout(function(data) {
        $rootScope.login();
    });
  }
}

$rootScope.showAlert = function(message, title, labels, callback) {
  var bl = (labels) ? labels : currentLocale.OK;
  var t = (title) ? title : "";
  var cb = (callback) ? callback : function(){};
  navigator.notification.alert(
    message,
    cb,
    t,
    bl
  );
}


$scope.handleBack = function(e){
  alert("back button tapped");
  if ( $location.url() == "/" ) {
    if (navigator.notification.confirm("Are you sure you want to exit?")) {
      navigator.app.exitApp();
    }
    else {
      return false;
    }
  }
  else if( $location.url() == "/home" ) {
    $rootScope.back();
    $window.localStorage.clear();
  }
  else{
    $rootScope.back();
  }
}
}])

我得到&#34;输入handleBackButton&#34;警告,但它没有在$ scope.handleBack()中输入警报。

我做错了什么????

1 个答案:

答案 0 :(得分:0)

public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);

          String S = sc.nextLine();
          int n = S.length();
          char ch[] = S.toCharArray();
          int lastReversedChar = n - 1;
          for(int i = 0; i<n; i++) {

              if(ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o' || ch[i] == 'u'
              || ch[i] == 'A' || ch[i] == 'E' || ch[i] == 'I' || ch[i] == 'O' || ch[i] == 'U'){
                  for(int j = lastReversedChar; j>i; j--) {
              if(ch[j] == 'a' || ch[j] == 'e' || ch[j] == 'i' || ch[j] == 'o' || ch[j] == 'u'
              || ch[j] == 'A' || ch[j] == 'E' || ch[j] == 'I' || ch[j] == 'O' || ch[j] == 'U') {
                  char temp = ch[j];
                  ch[j] = ch[i];
                  ch[i] = temp;
                  lastReversedChar = j - 1;
                  break;
         }
         } 
         } 
         }
            System.out.println(ch);

这样使用。