我有以下工厂和控制器:
(function () {
'use strict';
angular.module('app.core')
.factory('Auth', ['$http', function AuthFactory($http) {
return {
NavAuth: function (Tab) {
return $http({ method: 'GET', url: 'Dashboard/AuthorizeNavItem', params: { Name: Tab } });
}
}
}]);
})();
angular
.module('myapp')
.controller('IndexController', ['fuseTheming', 'msNavigationService', 'Auth', function (fuseTheming, msNavigationService, Auth) {
var vm = this;
//Define the tabs
msNavigationService.saveItem('app', {
title: 'QPSTool',
group: true,
weight: 1
});
msNavigationService.saveItem('app.dashboard', {
title: 'Dashboard',
icon: 'icon-tile-four',
state: 'app.dashboard',
weight: 1
});
Auth.NavAuth('IT').success(function (result) {
if (result == 'Authorized') {
msNavigationService.saveItem('app.it', {
title: 'IT',
icon: 'icon-monitor',
weight: 2
});
}
});
Auth.NavAuth('Users').success(function (result) {
if (result == 'Authorized') {
msNavigationService.saveItem('app.it.users', {
title: 'Users',
state: 'app.it.users',
weight: 1
});
}
});
Auth.NavAuth('Admin').success(function (result) {
if (result == 'Authorized') {
msNavigationService.saveItem('app.admin', {
title: 'Admin',
icon: 'icon-radioactive',
weight: 3
});
}
});
Auth.NavAuth('NavControl').success(function (result) {
if (result == 'Authorized') {
msNavigationService.saveItem('app.admin.navcontrol', {
title: 'Navigation Auth',
state: 'app.admin.navcontrol',
weight: 1
});
}
});
// Data
vm.themes = fuseTheming.themes;
}]);
工厂方法 NavAuth 所做的是将导航项目名称作为参数并告诉我们是否允许用户访问该项目。
我遇到的问题是,在控制器中,当我使用msNavigationService.saveItem
数据时,数据是以随机顺序返回的。NavControl
所以它会返回之前的授权IT
。
这会导致侧边导航无法正确呈现。
我如何做到这一点,以便事情按照我在控制器中指定的顺序运行(即我如何让它等到一个完成后再做另一个)?