【发布时间】:2016-01-25 19:58:07
【问题描述】:
我目前正在使用 Ionic 框架开发一个应用程序,但遇到了以下问题:
在应用程序的每个页面中,都应该有一个可用的左侧菜单。在只有一个页面(“事件”)中,右侧应该有另一个侧边菜单。 现在一切正常,直到我访问了一次“事件”页面:从那时起,当向左滑动时,每个页面上都会显示一个空白的右侧菜单 - 当然,它不应该在那里。
由于我不确定我是否足够好地解释了这种行为,所以我制作了一个快速的 codepen 供您查看应用程序和我的完整 code。
谢谢!
这里有重要的代码片段:
index.html:
<body ng-controller="MainCtrl" ng-app="ionicApp">
<ion-side-menus>
<!--- NAV-MENU LEFT --->
<ion-side-menu side="left">[...]</ion-side-menu>
<!--- EVENTS-MENU RIGHT --->
<ion-side-menu side="right" ng-if="showRightMenu">[...]</ion-side-menu>
<ion-side-menu-content>
<!--- HEADER --->
<ion-nav-bar class="bar bar-header bar-positive">
<ion-nav-buttons side="left">
<button class="button button-clear icon ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-clear icon ion-gear-a" ng-if="showRightMenu" menu-toggle="right"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</ion-side-menu-content>
</ion-side-menus>
<script id="home.html" type="text/ng-template">[...]</script>
<script id="events.html" type="text/ng-template">[...]</script>
</body>
app.js:
var app = angular.module('ionicApp', ['ionic', 'ionicApp.controllers']);
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'home.html'
})
.state('events', {
url: '/events',
templateUrl: 'events.html'
});
$urlRouterProvider.otherwise('/');
});
[...]
app.controller('MainCtrl', function($scope, $state, $rootScope) {
[...]
//set ng-if-variable for the right side menu
$rootScope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams) {
if (toState.name == 'events') {
$scope.showRightMenu = true;
} else {
$scope.showRightMenu = false;
}
//console.log($scope.showRightMenu);
})
function ContentController($scope, $ionicSideMenuDelegate) {
$scope.toggleLeft = function() {
$ionicSideMenuDelegate.toggleLeft();
};
$scope.toggleRight = function() {
$ionicSideMenuDelegate.toggleLeft();
};
}
});
[...]
【问题讨论】:
标签: javascript angularjs ionic-framework ionic