0
我正在使用吴开关如下。这是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-开关。我不想使用ng-hide/ng-show。
显示变量'$ scope.userRole'在'的console.log()'。因为'ng-switch'按预期工作。 [jsfiddle]上的示例(https://jsfiddle.net/Stepan_Kasyanenko/zcqsepxr/)。 –