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);
})