我有一个 Ionic app ,它有标签+菜单,这个问题特定于菜单。
我在 index.html 中定义我的侧边菜单,就像这样
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/routes.js"></script>
<script src="js/services.js"></script>
<script src="js/directives.js"></script>
</head>
<body ng-app="app" animation="slide-left-right-ios7">
<div>
<ion-side-menus enable-menu-with-back-views="false" data-componentid="side-menu21">
<ion-side-menu-content>
<ion-nav-bar class="bar-assertive">
<ion-nav-back-button class="button-icon icon ion-ios-arrow-back"> </ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
<button class="button button-icon button-clear ion-android-notifications" menu-toggle="right" ></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left" id="side-menu21">
<ion-header-bar class="bar-assertive">
<div class="title">Menu</div>
</ion-header-bar>
<ion-content padding="false" class="side-menu-left has-header">
<ion-list id="menu-list2" class=" " data-componentid="list2">
<ion-item id="menu-list-item1" ui-sref="myProfile">
<i class="icon ion-person" ></i> My Profile </ion-item>
<ion-item id="menu-list-item15" ui-sref="broadcast ">
<i class="icon ion-contrast" ></i> Broadcast </ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
</div>
</body>
</html>
我有一个服务,它以登录触发,它带给我我的权力
{ "authorities":
[
"myProfile","broadcast"
]
}
我稍后会像
那样存储在 localstorage 中window.localStorage.setItem("authority", data.authorities);
我想要做的是,根据我从登录获得的权限动态显示或隐藏菜单?
例如在权限中,如果代替"myProfile","broadcast"
只有"myProfile"
,则不应在侧边菜单中显示广播。
答案 0 :(得分:1)
您可以使用cordova build <platform>
或ng-hide
指令。
ng-if
然后在控制器中有一个功能
<ion-item ng-if="hasAuthority('broadcast')" id="menu-list-item15" ui-sref="broadcast ">
<i class="icon ion-contrast" ></i> Broadcast
</ion-item>