从标签按钮开sidemenu(Open sidemenu from a tab button)

2019-09-26 13:26发布

我想从一个标签按钮打开sidemenu。 控制台输出“打开菜单”,所以我知道服务方法被调用,但它根本不会打开菜单。 我在哪里去了?

这是我的tabs.html

<ion-tabs class="tabs-super-top tabs-top tabs-icon-left tabs-striped">

    <ion-tab title="More" icon="icon ion-navicon" ng-click="openSideMenu()" >
    </ion-tab>

    <ion-tab title="Events" icon="icon ion-calendar" ui-sref="tab.events">
        <ion-nav-view name="tab-events" class="slide-left-right"  ion-side-menu-content></ion-nav-view>
    </ion-tab>

    <ion-tab title="Involved" icon="icon ion-checkmark-round" ui-sref="tab.involved">
        <ion-nav-view name="tab-involved" class="slide-left-right" ion-side-menu-content></ion-nav-view>
    </ion-tab>

    <ion-tab title="Networks" icon="icon ion-network" ui-sref="tab.networks">
        <ion-nav-view name="tab-networks" class="slide-left-right" ion-side-menu-content></ion-nav-view>
    </ion-tab>


</ion-tabs>

navigation.js模块:

angular.module('navigationModule', [])
.controller('SideMenuController', function($scope, sideMenuService) 
{
    $scope.openSideMenu = function()
    {
        sideMenuService.openSideMenu('sideMenu');
    };
})


.service('sideMenuService', function($ionicSideMenuDelegate) {
    return {
        openSideMenu: function(menuhandle) 
        {
            console.log('open menu');
            return $ionicSideMenuDelegate.$getByHandle(menuhandle).toggleLeft();
        }
    }
})

;

目前,我有我的sidemenu index.html中:

<ion-side-menus side="left" delegate-handle="sideMenu">

    <!-- Center content -->
    <ion-side-menu-content>
        <ion-list>
            <ion-item nav-clear menu-close ng-click="login()">Login</ion-item>
            <ion-item nav-clear menu-close href="#/app/search">Search</ion-item>
            <ion-item nav-clear menu-close href="#/app/browse">Browse</ion-item>
            <ion-item nav-clear menu-close href="#/app/playlists">Playlists</ion-item>
        </ion-list>
    </ion-side-menu-content>

    <!-- Left menu -->
    <ion-side-menu side="left"></ion-side-menu>

    <!-- Right menu -->
    <ion-side-menu side="right"></ion-side-menu>

</ion-side-menus>

这是我的状态:

$stateProvider

    .state('tab', {
      url: "/tab",
      abstract: true,
      templateUrl: "templates/common/Tabs.html",
      controller: 'SideMenuController'
    })

Answer 1:

修复。 如果别人绊倒在这里... HTML布局是关键。

关键是把像这样的离子侧面菜单内容块内的HTML。

<ion-side-menus delegate-handle="sideMenu">

    <!-- Center content -->
    <ion-side-menu-content>

        <ion-nav-bar class="bar-dark nav-title-slide-ios7">
            <ion-nav-back-button class="button-clear">
                <i class="ion-arrow-left-c"></i> Back
            </ion-nav-back-button>
            <h1 class="title"></h1>
            <div class="buttons pull-right">
                <button class="ion-search button icon button-clear" ng-click="openModal()"></button>
                <button class="ion-plus-circled button icon button-clear" ng-click="openModal()"></button>
            </div>
        </ion-nav-bar>

        <ion-tabs class="tabs-super-top tabs-top tabs-icon-left tabs-striped">

            <ion-tab title="More" icon="icon ion-navicon" ng-click="openSideMenu()" >
                <!-- <ion-nav-view name="tab-more" class="slide-left-right"></ion-nav-view> -->
            </ion-tab>

            <ion-tab title="Events" icon="icon ion-calendar" ui-sref="tab.events">
                <ion-nav-view name="tab-events" class="slide-left-right"></ion-nav-view>
            </ion-tab>

            <ion-tab title="Involved" icon="icon ion-checkmark-round" ui-sref="tab.involved">
                <ion-nav-view name="tab-involved" class="slide-left-right"></ion-nav-view>
            </ion-tab>

            <ion-tab title="Networks" icon="icon ion-network" ui-sref="tab.networks">
                <ion-nav-view name="tab-networks" class="slide-left-right"></ion-nav-view>
            </ion-tab>

        </ion-tabs>


    </ion-side-menu-content>

    <!-- Left menu -->
    <ion-side-menu side="left">
        <ion-list>
            <ion-item nav-clear menu-close ng-click="login()">Login</ion-item>
            <ion-item nav-clear menu-close href="#/app/search">Search</ion-item>
            <ion-item nav-clear menu-close href="#/app/browse">Browse</ion-item>
            <ion-item nav-clear menu-close href="#/app/playlists">Playlists</ion-item>
        </ion-list>
    </ion-side-menu>

    <!-- Right menu -->
    <ion-side-menu side="right"></ion-side-menu>

</ion-side-menus>


Answer 2:

好吧,我离开了工作的切换。

首先,我增加了一个明确的控制只是为了sidemenus,就像这样:

<ion-side-menus delegate-handle="sideMenu" ng-controller="SideMenuController">

然后在controllers.js:

.controller('SideMenuController', function($scope, $ionicSideMenuDelegate) 
{
    $scope.openSideMenu = function()
    {
        $ionicSideMenuDelegate.$getByHandle('sideMenu').toggleLeft();
    };
})

而摆脱了的sideMenuService

检查文档在这里 。



Answer 3:

你传递false.toggleLeft ,其中明确告诉它不要开...

因此,只要将其更改为.toggleLeft()



文章来源: Open sidemenu from a tab button