我有了一个JSP页面上的角应用:
ng-init="role='<%=String.valueOf(session.getAttribute("role"))%>'"
所以body标签看起来像这样当JSP拉会话中的角色属性:
<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
那条路上经过。
有没有办法以这种方式访问范围变量,或者有另一种方式来实现这一点?
您无法访问$范围之控制器或向链路的功能。 – Raulucco
如果是关于认证角色,可以将变量附加到像[authenticate:true]这样的路由(https://github.com/DaftMonk/generator-angular-fullstack/blob/master/app/templates/client/app/帐户(身份验证)/帐户(js).js),可[重定向](https://github.com/DaftMonk/generator-angular-fullstack/blob/master/app/templates/client/app/app(js) .js)到app.run方法中的登录页面 – YOU