NG-重复Angularjs内NG-开关 [英] ng-switch inside ng-repeat Angularjs
问题描述
我有问题如何使用NG-NG开关重复内,使用范围为接通?
i have question how to use ng-switch inside ng-repeat and use scope for switch-on ?
例如:
<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 :
$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-开关时={{item.filter}}&LT上; - 不承认。输出是一样的code NG-动开关,当={{item.filter}}insted的音乐。我能做什么 ? THX的anwsers!
so the problem is on ng-switch-when = "{{item.filter}}" <-- does not recognize. the output is the same as code ng-swith-when="{{item.filter}}" insted of music. What can i do ? thx for anwsers !
〔实施例图片&LT; - 上为菜单和udner 50像素高度的子菜单,没有现在的内容...
exmaple picture <--upper is menu and udner 50px height is submenu with no content now ...
推荐答案
从 NG-开关
的文档:
请注意,要匹配的属性值,不能前pressions。他们是PTED作为文字字符串值来匹配间$ P $。例如, NG-开关时=someVal
将匹配字符串someVal
不违背价值恩pression的 $ scope.someVal
。
Be aware that the attribute values to match against cannot be expressions. They are interpreted as literal string values to match against. For example,
ng-switch-when="someVal"
will match against the string"someVal"
not against the value of the expression$scope.someVal
.
考虑使用 NG-如果
而不是:
<div class="animate-switch" ng-if="item.filter === 'music'">
filter equals 'music'
</div>
这篇关于NG-重复Angularjs内NG-开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!