Reputation: 97
I am trying to use ng-if in ng-repeat for implementing Accordions. Based upon the condition value, the ng-repeat should skip some items in ng-repeat.
E.g. If the item.condition is true then only it should display accordion. The code below is what I have so far and it is not working. Does it look right?
<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>
Upvotes: 6
Views: 2541
Reputation: 136154
Your ng-if
contain double extra quotes, It should be ng-if="item.condition == true"
, Also remove the ,
from the accordion element
Also you could minimize your condition to ng-if="item.condition"
so then expression will return true
and false
on item.condition
variable evaluation.
Markup
<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>
Upvotes: 5