次のファクトリとコントローラーがあります。
(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
ます。
これにより、サイド ナビゲーションが正しくレンダリングされません。
コントローラーで指定した順序で物事が実行されるようにするにはどうすればよいですか (つまり、一方が完了するまでもう一方を待機させるにはどうすればよいですか)。