0

My question is about angular routing. In fact I work on SPA application and the templateUrl of the first page depends on user roles (this information I have it in the user service). As I cannot inject services in app.config how can I get the use roles information in this part to decide which url to return?

It means for the same route .when('/') I have two or more templateUrl depends on user roles

  • You can use a function for templateURL, and that is injected with the route parameters. You can change the route parameters based on roles. – Amy Blankenship May 05 '16 at 23:11
  • Yeah, I've made a function for templateURL, but my problem is in the user role how to get it in this function? – user202493 May 10 '16 at 03:33

1 Answers1

0

It is possible to pass route parameters with this syntax:

$routeProvider.
  when('/:UserRole' {
    templateUrl: 'anyPage.html',
    controller: 'anyController'
  });

Inside your controller (in this case "anyController") the route params can be queried by injecting the $routeParams service:

angular.module('yourAppName')
  .controller('controllerName', ['$routeParams','yourService', function($routeParams, yourService){
     //call your service function with the routeParams
     yourService.serviceFunction($routeParams)
  }]);
Martin Godzina
  • 1,470
  • 11
  • 17