que1326 que1326 - 4 days ago 6
AngularJS Question

Access url in routeProvider in AngularJs 1

I am using AngularJs#1.3.8 with ngRoute injected in my main module. So, giving the current route:

.when('/users', {
templateUrl : 'template.html',
controller: 'Users',
controllerAs : 'Users',
resolve: {
function (userService) {
return userService.initModuleRoles('/users', ['R-USERS']);
}
}


In the service method initModuleRoles the first parameter: '/users' can be replace with non hard coded variable ? (something like $route.url)

Answer

You can pass params to your resolve:

    .when('/users', {
      templateUrl: 'template.html',
      controller: 'Users',
      controllerAs: 'Users',
      resolve: {
        lazy: ['userService','$location', function(userService,$location) {
          return userService.initModuleRoles($location.url(), ['R-USERS']);
        }]
      }
    });

Comments