我正在尝试在ng-repeat中使用ng-if来实现Accordions。根据条件值,ng-repeat应跳过ng-repeat中的一些项目。
E.g。如果item.condition为true,则只显示accordion。 下面的代码是我到目前为止,它没有工作。看起来不错吗?
<accordion close-others="true">
<accordion-group is-open="isopen" ng-repeat="item in items | limitTo:2" ng-if="item.condition == "true"",ng-init="isopen=2">
<accordion-heading>
{{item.label}}
<i class="pull-right glyphicon"
ng-class="{'icon-arrow-up': isopen, 'icon-arrow-down': !isopen}"></i>
</accordion-heading>
</accordion-group>
</accordion>
答案 0 :(得分:5)
您的ng-if
包含双倍额外引号,应为ng-if="item.condition == true"
,同时从手风琴元素中移除,
此外,您可以将条件最小化为ng-if="item.condition"
,然后表达式将在true
变量评估中返回false
和item.condition
。
<强>标记强>
<accordion close-others="true">
<accordion-group is-open="isopen" ng-repeat="item in items | limitTo:2"
ng-if="item.condition" ng-init="isopen=2">
<accordion-heading>
{{item.label}}
<i class="pull-right glyphicon" ng-class="{'icon-arrow-up': isopen, 'icon-arrow-down': !isopen}"></i>
</accordion-heading>
</accordion-group>
</accordion>