我在 JSP 页面上有一个 Angular 应用程序,它具有:
ng-init="role='<%=String.valueOf(session.getAttribute("role"))%>'"
因此,当 JSP 从会话中提取角色属性时,body 标记将如下所示:
<body ng-app="appName" ng-init="role='roleName'">
我想role在$routeProvider.
我尝试通过传递$scope给app.config函数来这样做:
app.config(['$routeProvider', '$scope',
function ($routeProvider, $scope) {
$routeProvider
.when('somePath' {
...
})
.when('someOtherPath' {
...
})
.otherwise({
redirectTo: $scope.role == 'goodRole' ? 'somePath' : 'someOtherPath'
});
}]);
但是,您似乎无法以$scope这种方式通过。
有没有办法以这种方式访问范围变量,还是有另一种方法来完成这个?