【发布时间】:2014-04-03 20:12:25
【问题描述】:
我正在尝试根据存储在父范围中的布尔值有条件地显示指令。我不知道为什么下面不起作用。 “不工作”是指两个指令都没有显示。
<ul class="nav navbar-nav pull-right" ng-switch="userIsAuthenticated">
<account-item item="accountMenuItem" ng-repeat="accountMenuItem in anonymousMenuItems" ng-switch-when="false"></account-item>
<account-item item="accountMenuItem" ng-repeat="accountMenuItem in authenticatedMenuItems" ng-switch-when="true"></account-item>
</ul>
即使在我的测试用例中“userIsAuthenticated”设置为“false”,也不会显示任何指令。如果我在指令上方添加{{userIsAuthenticated}},则会按预期输出'false'。
我也试过这个:
<ul class="nav navbar-nav pull-right" ng-switch={{userIsAuthenticated}}>
<account-item item="accountMenuItem" ng-repeat="accountMenuItem in anonymousMenuItems" ng-switch-when={{false}}></account-item>
<account-item item="accountMenuItem" ng-repeat="accountMenuItem in authenticatedMenuItems" ng-switch-when={{true}}></account-item>
</ul>
如果我从它们将显示的任一指令中删除条件 ng-switch-when 属性。所以我知道问题出在我的 ng-switch 上。
【问题讨论】:
-
你能显示
account-item指令中的内容吗?
标签: javascript angularjs ng-switch