【发布时间】:2016-03-11 11:58:06
【问题描述】:
我正在使用 ng-switch,如下所示。这是ng-switch的正确用法吗?我不希望它在数组中,因为我将它与范围变量一起使用。
在我的 HTML 中,我已将其定义如下。 userRole 是我希望我的搜索所基于的变量,在 when 中我使用了基于我的 div 标签内容应该使用的值。
<div ng-switch on ="userRole">
<div ng-switch-when="admin">
[...]
</div>
<div ng-switch-when="user">
[...]
</div>
我无法访问 ng-switch 的功能,我的整个内容部分都消失了。
在我的 .js 文件中,我定义了以下内容:
if(loginModel.authorities[0].authority=="ROLE_ADMIN"){
console.log("Me here");
$scope.userRole="admin";
}
else
if(loginModel.authorities[0].authority=="ROLE_USER"){
$scope.userRole="user";
}
else{
$scope.userRole="guest";
}
但是我的屏幕没有显示任何东西,这让我想知道我应该如何使用 ng-switch。我不想使用 ng-hide / ng-show。
【问题讨论】:
-
在
console.log()中显示变量$scope.userRole。因为ng-switch按预期工作。 jsfiddle 上的示例。