1

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 :)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Amir
  • 211
  • 3
  • 14
  • 1
    The answer in this post is what you are looking for http://stackoverflow.com/questions/22537311/angular-ui-router-login-authentication – jbrown Nov 21 '16 at 16:34
  • I have implemented like in this thread, using resolve (in resolve: $state.go(module2); deferred.reject('no privilege'); so users cannot access the page they are not allowed to. Problem is that still these pages are rendered in 'main menu' and I would like them to be hidden. – Amir Nov 22 '16 at 08:51

0 Answers0