我在JSP页面上有一个有角度的应用程序,该应用程序具有:
ng-init="role='<%=String.valueOf(session.getAttribute("role"))%>'"
因此,当JSP从会话中拉出role属性时,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
这种方式。
有没有办法以这种方式访问作用域变量,或者有另一种方法可以做到这一点?
不,这是不可能的。您如何将其设置为data-role
属性并从中获取它document.body.dataset.role
:
data-role="<%=String.valueOf(session.getAttribute("role"))%>"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句