title: AngularJS: accessing scope variables in $routeProvider
body: <p>I have an angular app on a JSP page that has:</p>
  
  <pre><code>ng-init="role='&lt;%=String.valueOf(session.getAttribute("role"))%&gt;'"
  </code></pre>
  
  <p>So the body tag will look like this when the JSP pulls the role attribute from the session:</p>
  
  <pre><code>&lt;body ng-app="appName" ng-init="role='roleName'"&gt;
  </code></pre>
  
  <p>I want to access this <code>role</code> variable in the <code>$routeProvider</code>.</p>
  
  <p>I tried doing so by passing <code>$scope</code> to the <code>app.config</code> function as such:</p>
  
  <pre><code>app.config(['$routeProvider', '$scope',
      function ($routeProvider, $scope) {
          $routeProvider
          .when('somePath' {
              ...
          })
          .when('someOtherPath' {
              ...
          })
          .otherwise({
              redirectTo: $scope.role == 'goodRole' ? 'somePath' : 'someOtherPath'
          });
  }]);
  </code></pre>
  
  <p>However, it appears that you cannot pass in the <code>$scope</code> that way.</p>
  
  <p>Is there a way to access a scope variable in this fashion, or is there another way to accomplish this?</p>