我們正在爲包含動態導航欄,角度本地存儲模塊,授權服務,數據服務和兩個部分,一個是導航欄部分,另一個是頁眉部分。我目前通過Authservice登錄用戶,然後通過http.get調用從服務器獲取導航元素。然後將該值存儲在名爲navElements的localStorage元素中。代碼如下:
指數:
<div class="main-container">
<aside data-ng-include=" 'views/nav.html' "
id="nav-container"
class="nav-container"
data-ng-class=" {'nav-fixed': admin.fixedSidebar, 'nav-horizontal': admin.menu === 'horizontal', 'nav-vertical': admin.menu === 'vertical'}"
>
</aside>
<div id="content" class="content-container">
<section data-ng-view
class="view-container {{admin.pageTransition.class}}"></section>
</div>
</div>
登錄/導航元素放置
apiRequest(API_URL + 'Navigation').then(
function(event){
console.log(event);
localStorageService.set("navElements", event);
modalInstance.close();
deferred.resolve(response);
$location.url('/dashboard');
}
導航HTML
<div class="nav-wrapper" data-ng-controller="DashboardCtrl">
<ul id="nav"
class="nav"
data-slim-scroll
data-collapse-nav
data-highlight-active>
<li ng-if="initialized"><a href="#/dashboard"> <i class="ti-home"></i><span data-i18n="Dashboard"></span> </a></li>
<li ng-repeat="nav in navList">
<a href="{{nav.ButtonPath}}" disabled>
<i class="{{nav.IconPath}}"></i>
<span data-i18n="{{nav.Title}}"></span>
</a>
<ul>
<li ng-repeat="link in nav.Children">
<a href="{{link.NavigationUrl}}">
<i class="ti-angle-right"></i>
<span data-i18n="{{link.Title}}"></span>
</a>
</li >
</ul>
</li>
</ul>
而且儀表板控制器導航李ST分配:
angular.module('app.DashboardCtrl', []).controller('DashboardCtrl',function ($q, $http, $scope, $location, $route, $window, $modal, dataService, logger, localStorageService) {
$scope.editMode=false;
$scope.Rows = {};
$scope.currentLocation = "";
console.log($scope);
$scope.navList = localStorageService.get("navElements");
奇怪的是,重新加載頁面後的元素出現,但在清除Cookie後首次登錄時,導航元素不存在。但是,nav元素駐留在控制器的$ scope中,$ scope。$ apply不起作用,即使超時。另外一個console.log顯示$ scope.navList是在用戶登錄並被帶到儀表板視圖時定義的。我對這個問題非常難過,任何幫助/建議都會很棒。這個問題也存在於網頁的另一部分,所以我懷疑它們是相關的。