我有问题如何在ng-repeat中使用ng-switch并使用范围进行开启?
示例:
<div ng-repeat="item in submenu">
<div class="animate-switch" ng-switch-when="{{item.filter}}">
<div class="navbar navbar-default navbar-static-top {{item.filter}}">
<div class="navbar-collapse collapse" id="navbar-{{item.filter}}">
<ul class="nav navbar-nav subnav">
<li ng-repeat="subitem in item.sub" class="items" >
<a ng-href="{{subitem.link}}" class="{{selected }}" ng-click="selectfiltersub(subitem.filter)">{{item.name}}</a>
</li>
</ul>
</div>
</div>
</div>
</div>
$ scope.submenu:
$scope.submenu =[{
name:'Glasba',
filter:'music',
sub:[{
name:'Koncerti',
filter:'Concerts'
},{
name:'Klasika',
filter:'Clasic'
},{
name:'Elektronika',
filter:'Elektro'
},{
name:'Indy',
filter:'Indy'
},{
name:'Teater',
filter:'Theater'
}]
}]
所以问题出在ng-switch-when =“{{item.filter}}”&lt; - 无法识别。输出与代码ng-swith-when =“{{item.filter}}”的音乐相同。我能做什么 ? thx for thewsers!
exmaple picture &lt; - upper是menu and udner 50px height是子菜单,现在没有内容......
答案 0 :(得分:2)
来自ng-switch
documentation:
请注意,要匹配的属性值不能是表达式。它们被解释为要匹配的文字字符串值。例如,
ng-switch-when="someVal"
将匹配字符串"someVal"
,而不是与表达式$scope.someVal
的值匹配。
请改为使用ng-if
:
<div class="animate-switch" ng-if="item.filter === 'music'">
filter equals 'music'
</div>