I am using Angular UI-router and would like to add state if user has privilege to view page.
Example code, for module1.route.js:
(function() {
'use strict';
angular
.module('module1.route',['ui.router'])
.config(['$stateProvider', configRoute]);
function configRoute($stateProvider) {
$stateProvider
.state('module1', {
url: '/module1',
views: {
'': { // template to display in the main view
templateUrl: 'module1.html',
controller: 'Module1Controller as vm'
}
});
}
})();
I have e.g. 5 modules with this same code and they are 'main menu selection'.
I would like to define/add state only if current user has privilege/role for module1.
In .config I cannot inject my model or service with $http (which gets the privilege from web service).
How can I add state depending on current-user role?
Note 1: This is an Angular 1 project
Note 2: I am new to Angular so please write answers/suggestions in details :)