我使用angular来提取内容并在网站的某些页面上显示。我在标题中有自举下拉菜单。根据用户登录,隐藏了一些下拉选项。为实现这一点,我在头控制器上使用了ng-if。一切正常。
但问题是,有时当我打开网站时,我也能看到隐藏的下拉选项,{{userRole}}显示为{{userRole}}。为什么会这样?谢谢。
Screen shot of issue 在屏幕截图中,用户可以看到两个我的个人资料图标。
var itpApp = angular.module("itpApp",['ngRoute','angular.filter','ui.bootstrap','ngSanitize']);
itpApp.controller("headerController", function($scope, $rootScope) {
var gaR = new GlideAjax('ITPortalUtil0');
gaR.addParam('sysparm_name','u_role');
gaR.getXML(function(response) {
$rootScope.userRole = response.responseXML.documentElement.getAttribute("answer");
$rootScope.$apply();
console.log('user role check: '+$rootScope.userRole);
//$rootScope.userRole = $localStorage.user_role;
});
});
<div class="navbar navbar-default1" ng-controller="headerController">
<div class="navbar-collapse collapse" id="shortMenu">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">My Tickets$[SP]<b class="caret"></b></a>
<ul class="dropdown-menu" id="menu7">
<li ng-if="userRole =='ess'"><a href="#" role="button" data-toggle="modal" data-target="#myModal" >My Profile</a></li>
<li ng-if="userRole =='itil'"><a href="/portal/my_profile.do?sysparm_id=${user.sys_id}">My Profile</a></li>
</ul>
</li>
</ul>
</div>