如何检测 ionicSideMenu 何时打开?

How to detect when ionicSideMenu is open?

http://codepen.io/leongaban/pen/PPLVNY?editors=101

我正在尝试在离子应用程序中在左侧面板打开时更改标志变量

found this 并尝试实现它,但是变量没有改变 而且我 没有看到 console.log声明.

标记

<script id="templates/home.html" type="text/ng-template">
  <ion-view view-title="Welcome">
    <ion-content class="padding">
      <h1>{{changeMe}}</h1>
      <p>Swipe to the right to reveal the left menu.</p>
      <p>(On desktop click and drag from left to right)</p>
    </ion-content>
  </ion-view>
</script>

控制器

.controller('MainCtrl', function($scope, $ionicSideMenuDelegate, $ionicPlatform) {
  $scope.changeMe = "This should change if left panel is open"
  $scope.attendees = [
    { firstname: 'Nicolas', lastname: 'Cage' },
    { firstname: 'Jean-Claude', lastname: 'Van Damme' },
    { firstname: 'Keanu', lastname: 'Reeves' },
    { firstname: 'Steven', lastname: 'Seagal' }
  ];

  $scope.toggleLeft = function() {
    $ionicSideMenuDelegate.toggleLeft();
  };

  $ionicPlatform.registerBackButtonAction(function (event) {
    $ionicSideMenuDelegate.toggleLeft();
    $ionicSideMenuDelegate.$getByHandle('sideMenu').toggleLeft();
    $timeout ( function() {
      $scope.changeMe = "CHANGED! Left panel is open!";
      console.log ("Status of SIDE MENU IS : " + $ionicSideMenuDelegate.$getByHandle('sideMenu').isOpen());
    },1000);   
  }, 100);
})

也试过这个:

.run(function($ionicPlatform, $ionicSideMenuDelegate) {
  $ionicPlatform.registerBackButtonAction(function(e) {
    e.preventDefault();
    if (!$ionicSideMenuDelegate.isOpen()) {
      console.log('isOPEN!');
    }

    if (!$ionicSideMenuDelegate.isOpenLeft()) {
      console.log('OPEN!');
      $ionicSideMenuDelegate.toggleLeft();
    } else {
      console.log('Closed!');
    }
  }, 1000);   
})

getOpenRatio 成功了! isOpen 没用,isOpenLeft 对我也没用。


$scope.$watch(function () {
  return $ionicSideMenuDelegate.getOpenRatio();
},
function (ratio) {
  if (ratio === 1){
    console.log('ratio is true');
    $scope.isActive= true;
  } else{
    $scope.isActive = false;
    console.log('ratio is false');
  }
});

更新:刚刚也在我的实际应用中修复了它!我有 2 ion-side-menus 而不是只有 1.

<ion-side-menus class="ion-home">
    <!-- <ion-side-menus enable-menu-with-back-views="false"> -->

isOpenLeft() 正在和我一起工作。 :)
我正在使用以下代码来检测打开或关闭幻灯片菜单。

$scope.$watch(function () {
       return $ionicSideMenuDelegate.isOpenLeft();
      },
      function (isOpen) {
        if (isOpen){
          console.log("open");
        } else{
          console.log("close");
        }
     });