1

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

在此处输入图像描述

当左侧面板在离子应用程序中打开时,我试图更改标志变量。

找到了这个并尝试实现它,但变量没有改变,我没有看到 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);   
})
4

2 回答 2

2

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

$scope.$watch(function () {
       return $ionicSideMenuDelegate.isOpenLeft();
      },
      function (isOpen) {
        if (isOpen){
          console.log("open");
        } else{
          console.log("close");
        }
     });
于 2016-12-19T07:44:45.717 回答
1

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"> -->
于 2015-11-19T20:10:12.630 回答