我在 JSP 页面上有一个 Angular 应用程序,其中包含:
ng-init="role='<%=String.valueOf(session.getAttribute("role"))%>'"
因此,当 JSP 从会话中提取角色属性时,body 标记将如下所示:
<body ng-app="appName" ng-init="role='roleName'">
我想访问这个role
变量在$routeProvider
.
我尝试通过这样做$scope
to the app.config
函数如下:
app.config(['$routeProvider', '$scope',
function ($routeProvider, $scope) {
$routeProvider
.when('somePath' {
...
})
.when('someOtherPath' {
...
})
.otherwise({
redirectTo: $scope.role == 'goodRole' ? 'somePath' : 'someOtherPath'
});
}]);
但是,您似乎无法通过$scope
那样。
有没有一种方法可以以这种方式访问作用域变量,或者是否有其他方法可以实现此目的?
不,这是不可能的。你把它设置为一个怎么样data-role
属性并从中获取document.body.dataset.role
:
data-role="<%=String.valueOf(session.getAttribute("role"))%>"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)